Skip to content

Commit 1ccb037

Browse files
authored
Do not notify when updated bookmarks are empty
Also get rid of unnecessary bookmark copy
1 parent ff57111 commit 1ccb037

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

neo4j/bookmarks.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ type bookmarkManager struct {
7777
}
7878

7979
func (b *bookmarkManager) UpdateBookmarks(database string, previousBookmarks, newBookmarks Bookmarks) {
80+
if len(newBookmarks) == 0 {
81+
return
82+
}
8083
var bookmarksToNotify Bookmarks
8184
storedNewBookmarks := collection.NewSet(newBookmarks)
8285
if rawCurrentBookmarks, loaded := b.bookmarks.LoadOrStore(database, storedNewBookmarks); !loaded {
@@ -98,7 +101,7 @@ func (b *bookmarkManager) GetAllBookmarks() Bookmarks {
98101
allBookmarks.AddAll(b.supplier.GetAllBookmarks())
99102
}
100103
b.bookmarks.Range(func(db, rawBookmarks any) bool {
101-
bookmarks := rawBookmarks.(collection.Set[string]).Copy()
104+
bookmarks := rawBookmarks.(collection.Set[string])
102105
allBookmarks.Union(bookmarks)
103106
return true
104107
})

neo4j/bookmarks_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,21 @@ func TestBookmarkManager(outer *testing.T) {
152152
}
153153
})
154154

155+
outer.Run("does not notify updated bookmarks when empty", func(t *testing.T) {
156+
initialBookmarks := []string{"a", "b"}
157+
bookmarkManager := neo4j.NewBookmarkManager(neo4j.BookmarkManagerConfig{
158+
InitialBookmarks: map[string]neo4j.Bookmarks{"db1": initialBookmarks},
159+
BookmarkUpdateNotifier: func(db string, bookmarks neo4j.Bookmarks) {
160+
t.Error("I must not be called")
161+
},
162+
})
163+
164+
bookmarkManager.UpdateBookmarks("db1", initialBookmarks, nil)
165+
166+
actualBookmarks := bookmarkManager.GetBookmarks("db1")
167+
AssertEqualsInAnyOrder(t, actualBookmarks, initialBookmarks)
168+
})
169+
155170
outer.Run("notifies updated bookmarks for existing DB without bookmarks", func(t *testing.T) {
156171
notifyHookCalled := false
157172
expectedBookmarks := []string{"a", "d"}

neo4j/internal/collection/set.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (set Set[T]) Values() []T {
5959
}
6060
result := make([]T, len(set), len(set))
6161
i := 0
62-
for value, _ := range set {
62+
for value := range set {
6363
result[i] = value
6464
i++
6565
}

0 commit comments

Comments
 (0)