From 28f3ca73d06e1c3b325b55077cf83dd1234b574f Mon Sep 17 00:00:00 2001 From: Justin Hawkins Date: Tue, 31 May 2022 08:40:44 +0930 Subject: [PATCH] Remove deleted bookmark words from the index --- .vscode/settings.json | 3 ++- db/bookmarks.go | 3 +++ db/index.go | 10 ---------- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index e2c499e..3a609b4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,7 @@ "linkwallet", "nicetime", "serialised", - "stopword" + "stopword", + "Upsert" ] } \ No newline at end of file diff --git a/db/bookmarks.go b/db/bookmarks.go index 759b22c..c68e019 100644 --- a/db/bookmarks.go +++ b/db/bookmarks.go @@ -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 } diff --git a/db/index.go b/db/index.go index 04ec394..14ecc2c 100644 --- a/db/index.go +++ b/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() }