Skip to content

Commit

Permalink
Fix bug where page updates would delete all indexed terms
Browse files Browse the repository at this point in the history
- See inline comment for more details.
- This became obvious from twitter pages which, after indexing, get updated due to a hook running to fetch their titles. Thus all twitter pages were losing their indexed terms.
- Another common case was updating a page's title in the dashboard. All other synced extensions would lose the terms for that page
  • Loading branch information
poltak committed Jun 25, 2024
1 parent a9b2084 commit 1ecca39
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/personal-cloud/background/handle-incoming-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ export const handleIncomingData = (deps: {
storageType,
collection,
updates,
where,
where: _where,
}: IncomingDataInfo): Promise<void> => {
let where = _where
const incomingStorageManager =
storageType === PersonalCloudClientStorageType.Persistent
? deps.persistentStorageManager
Expand Down Expand Up @@ -66,6 +67,24 @@ export const handleIncomingData = (deps: {
}
}

if (collection === 'pages') {
let existingPage = await deps.storageManager.backend.operation(
'findObject',
collection,
{ url: updates.url },
)
// This covers a bug we had for a long time where any page updates would result in text being deleted
// as pages coming from the translation layer never contain text. Text is fetched from a separate data source.
// Thus we remove it here so it's not included in the fields that will get overwritten in the update op, and also
// set the `where` clause so an update op happens instead of a create op (which overwrites everything).
//
// See the `docContent` collection clause in this function below for how text is fetched.
if (existingPage) {
delete updates['text']
where = { url: updates['url'] }
}
}

// WARNING: Keep in mind this skips all storage middleware
await updateOrCreate({
collection,
Expand Down

0 comments on commit 1ecca39

Please sign in to comment.