Remove deleted bookmark words from the index
This commit is contained in:
parent
a144c6b383
commit
28f3ca73d0
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -6,6 +6,7 @@
|
||||
"linkwallet",
|
||||
"nicetime",
|
||||
"serialised",
|
||||
"stopword"
|
||||
"stopword",
|
||||
"Upsert"
|
||||
]
|
||||
}
|
@ -45,7 +45,10 @@ func (m *BookmarkManager) DeleteBookmark(bm *entity.Bookmark) error {
|
||||
return fmt.Errorf("bookmark does not exist")
|
||||
}
|
||||
|
||||
// delete it
|
||||
m.db.store.DeleteMatching(bm, bolthold.Where("ID").Eq(bm.ID))
|
||||
// delete all the index entries
|
||||
m.db.UpdateIndexForWordsByID([]string{}, bm.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
10
db/index.go
10
db/index.go
@ -2,7 +2,6 @@ package db
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/tardisx/linkwallet/entity"
|
||||
bolthold "github.com/timshannon/bolthold"
|
||||
@ -21,15 +20,12 @@ func (db *DB) UpdateIndexForWordsByID(words []string, id uint64) {
|
||||
}
|
||||
|
||||
db.store.TxForEach(txn, &bolthold.Query{}, func(wi *entity.WordIndex) {
|
||||
// log.Printf("considering this one: %s", wi.Word)
|
||||
delete(wi.Bitmap, id)
|
||||
})
|
||||
|
||||
// adding
|
||||
var find, store time.Duration
|
||||
for i, word := range words {
|
||||
// log.Printf("indexing %s", word)
|
||||
tF := time.Now()
|
||||
thisWI := entity.WordIndex{Word: word}
|
||||
err := db.store.TxGet(txn, "word_index_"+word, &thisWI)
|
||||
if err == bolthold.ErrNotFound {
|
||||
@ -38,18 +34,13 @@ func (db *DB) UpdateIndexForWordsByID(words []string, id uint64) {
|
||||
} else if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
findT := time.Since(tF)
|
||||
|
||||
tS := time.Now()
|
||||
thisWI.Bitmap[id] = true
|
||||
// log.Printf("BM: %v", thisWI.Bitmap)
|
||||
err = db.store.TxUpsert(txn, "word_index_"+word, thisWI)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
findS := time.Since(tS)
|
||||
find += findT
|
||||
store += findS
|
||||
|
||||
if i > 0 && i%100 == 0 {
|
||||
txn.Commit()
|
||||
@ -60,7 +51,6 @@ func (db *DB) UpdateIndexForWordsByID(words []string, id uint64) {
|
||||
}
|
||||
|
||||
}
|
||||
//log.Printf("find %s store %s", find, store)
|
||||
|
||||
txn.Commit()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user