Closed jinzhongjia closed 2 years ago
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
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.
For example, I used 190ms for my first query, and then only used 120ms
Badger caches data internally
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
}
What do you mean by "doesn't seem to work"? What is your expected output and what are you getting?
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?
I see my problem. I didn't sort.
But when I sort it, its query speed slows down again.
Naturally, you have to take into account the cost of sorting
Okay, I'll start looking at the source code tomorrow. It is 50ms before sorting and 1.3s after sorting.😔
I found what the problem is. I'll release soon a fix for this
I found what the problem is. I'll release soon a fix for this
thanks ,bro
Can you post the snipped before and after sorting?
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.
But when I don't sort, skip won't achieve the effect of the next page as I thought.
I pulled the version I just submitted, then tested the count elapsed time and found that it didn't reduce much.
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.
bro, the fun
count( )
, when there is a lot of data, it takes a long time to return. and i see the source code ,it is implemented byfindall( )
andlen( )
the return it takes a lot time when the data is big such as ,now i have about 40,000 pieces of data. it takes more than a second... maybe we should change thefun
implementationit print this