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