Giter Club home page Giter Club logo

Comments (18)

ostafen avatar ostafen commented on September 15, 2024

Yes, I was aware about this, and this should be definitely optimized. Do you want to provide a PR?
The Count() function should be added to the StorageEngine interface{} and be implemented for the two storages currently available

from clover.

jinzhongjia avatar jinzhongjia commented on September 15, 2024

Yes, I was aware about this, and this should be definitely optimized. Do you want to provide a PR? The Count() function should be added to the StorageEngine interface{} and be implemented for the two storages currently available

Of course I want to provide pr, but I need to wait for me to read the code and ask by the way, will there be a cache for the query results? I noticed that the first query takes much longer than the later query.

from clover.

jinzhongjia avatar jinzhongjia commented on September 15, 2024

For example, I used 190ms for my first query, and then only used 120ms

from clover.

ostafen avatar ostafen commented on September 15, 2024

Badger caches data internally

from clover.

jinzhongjia avatar jinzhongjia commented on September 15, 2024

For some reason, my skip function doesn't seem to work. The code is as follows

func (here *Db) SearchContent(names []string, num int, pg int) []*clover.Document {
	var name string
	for i, v := range names {
		if i < len(names)-1 {
			name += "(.*" + regexp.QuoteMeta(v) + ".*)|"
		} else {
			name += "(.*" + regexp.QuoteMeta(v) + ".*)"
		}
	}
	fmt.Println(num, pg)
	query := here.content.Where(clover.Field("name").Like(name))

	startT := time.Now()

	docs, _ := query.Skip(num * pg).Limit(num).FindAll()
	fmt.Printf("time.Since(startT): %v\n", time.Since(startT))

	return docs
}

from clover.

ostafen avatar ostafen commented on September 15, 2024

What do you mean by "doesn't seem to work"? What is your expected output and what are you getting?

from clover.

jinzhongjia avatar jinzhongjia commented on September 15, 2024

What do you mean by "doesn't seem to work"? What is your expected output and what are you getting?

I expected to skip a few doc, but it didn't.
And then the findall function returns random disorder?

from clover.

jinzhongjia avatar jinzhongjia commented on September 15, 2024

I see my problem. I didn't sort.

from clover.

jinzhongjia avatar jinzhongjia commented on September 15, 2024

But when I sort it, its query speed slows down again.

from clover.

ostafen avatar ostafen commented on September 15, 2024

Naturally, you have to take into account the cost of sorting

from clover.

jinzhongjia avatar jinzhongjia commented on September 15, 2024

Okay, I'll start looking at the source code tomorrow.
It is 50ms before sorting and 1.3s after sorting.😔

from clover.

ostafen avatar ostafen commented on September 15, 2024

I found what the problem is. I'll release soon a fix for this

from clover.

jinzhongjia avatar jinzhongjia commented on September 15, 2024

I found what the problem is. I'll release soon a fix for this

thanks ,bro

from clover.

ostafen avatar ostafen commented on September 15, 2024

Can you post the snipped before and after sorting?

from clover.

jinzhongjia avatar jinzhongjia commented on September 15, 2024

Is it time-consuming to sort screenshots, or something else?
The part I want to sort is the above part of the code. I need to sort and query the data with a specified number of pages.

from clover.

jinzhongjia avatar jinzhongjia commented on September 15, 2024

But when I don't sort, skip won't achieve the effect of the next page as I thought.

from clover.

jinzhongjia avatar jinzhongjia commented on September 15, 2024

I pulled the version I just submitted, then tested the count elapsed time and found that it didn't reduce much.

from clover.

ostafen avatar ostafen commented on September 15, 2024

Actually this is the best we can do. Without indexes (which are not currently supported), there is no faster way than iterate on each record of the collection.

from clover.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.