Skip to content

Commit

Permalink
Add fix for orphaned annotListEntries in blank list search
Browse files Browse the repository at this point in the history
  • Loading branch information
poltak committed Jun 4, 2024
1 parent 89ca87f commit 93d28e4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/background-script/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ import ActivityIndicatorBackground from 'src/activity-indicator/background'
import SummarizeBackground from 'src/summarization-llm/background'
import ActivityStreamsBackground from 'src/activity-streams/background'
import { SyncSettingsBackground } from 'src/sync-settings/background'
import { AuthServices, Services } from 'src/services/types'
import { captureException } from 'src/util/raven'
import type { AuthServices, Services } from 'src/services/types'
import type { captureException } from 'src/util/raven'
import { PDFBackground } from 'src/pdf/background'
// import { FirebaseUserMessageService } from '@worldbrain/memex-common/lib/user-messages/service/firebase'
// import { UserMessageService } from '@worldbrain/memex-common/lib/user-messages/service/types'
Expand Down Expand Up @@ -285,9 +285,10 @@ export function createBackgroundModules(options: {
})

const search = new SearchBackground({
storageManager,
pages,
analyticsBG,
storageManager,
captureException: options.captureException,
})

const tags = new TagsBackground({
Expand Down
23 changes: 22 additions & 1 deletion src/search/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { PDF_PAGE_URL_PREFIX } from '@worldbrain/memex-common/lib/page-indexing/
import { EVENT_PROVIDER_URLS } from '@worldbrain/memex-common/lib/constants'
import { TWITTER_URLS } from '@worldbrain/memex-common/lib/twitter-integration/constants'
import { normalizeUrl } from '@worldbrain/memex-common/lib/url-utils/normalize'
import type { captureException } from 'src/util/raven'

export default class SearchBackground {
storage: SearchStorage
Expand Down Expand Up @@ -103,6 +104,7 @@ export default class SearchBackground {
storageManager: Storex
pages: PageIndexingBackground
analyticsBG: AnalyticsCoreInterface
captureException: typeof captureException
},
) {
this.storage = new SearchStorage({
Expand Down Expand Up @@ -520,11 +522,30 @@ export default class SearchBackground {
.table<Annotation>('annotations')
.bulkGet([...validAnnotIds])

let anyNonExistentAnnot = false
// Add in all the annotations to the results
const annotsByPage = groupBy(
[...autoSharedAnnots, ...selectivelySharedAnnots],
[...autoSharedAnnots, ...selectivelySharedAnnots]
// Sometimes annotListEntries can refer to annotations that were deleted due to old buggy delete logic
.filter((annot) => {
let annotExists = annot != null
if (annotExists) {
anyNonExistentAnnot = true
}
return annotExists
}),
(a) => a.pageUrl,
)

// Log it in sentry so we get an idea of how many times users have this case
if (anyNonExistentAnnot) {
this.options.captureException(
new Error(
`OwnError: Encountered annotListEntry referencing non-existent annotation`,
),
)
}

for (const [pageId, annots] of Object.entries(annotsByPage)) {
const descOrderedAnnots = annots.sort(
(a, b) => b.lastEdited.valueOf() - a.lastEdited.valueOf(),
Expand Down

0 comments on commit 93d28e4

Please sign in to comment.