A music player that connects to your cloud/distributed storage.
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: improve atproto syncing algo

+28 -10
+28 -10
src/components/transformer/output/raw/atproto-sync/element.js
··· 73 73 const tombstones = this.#getTombstones(name); 74 74 let tombstonesChanged = false; 75 75 76 - const oldCol = await Output.data(l[name]); 77 - if (oldCol && Array.isArray(oldCol.data)) { 78 - for (const record of oldCol.data) { 79 - if (!newIds.has(record.id) && !tombstones.has(record.id)) { 80 - tombstones.add(record.id); 81 - tombstonesChanged = true; 82 - } 76 + const existing = l[name].collection(); 77 + const existingArr = 78 + existing.state === "loaded" && Array.isArray(existing.data) 79 + ? existing.data 80 + : []; 81 + 82 + for (const record of existingArr) { 83 + if (!newIds.has(record.id) && !tombstones.has(record.id)) { 84 + tombstones.add(record.id); 85 + tombstonesChanged = true; 83 86 } 84 87 } 85 88 ··· 103 106 await l[name].save(newData); 104 107 105 108 if (remote.ready()) { 106 - remote[name].save(newData).then(() => { 109 + // Merge with any records added remotely since the last sync so we 110 + // don't accidentally overwrite them with our local-only view. 111 + const remoteCol = remote[name].collection(); 112 + const remoteArr = 113 + remoteCol.state === "loaded" && Array.isArray(remoteCol.data) 114 + ? remoteCol.data 115 + : []; 116 + const dataForRemote = this.#mergeRecords(name, newData, remoteArr); 117 + 118 + remote[name].save(dataForRemote).then(() => { 107 119 const rev = this.#atproto()?.rev(); 108 120 if (rev) this.#storeRev(rev); 109 121 this.#clearDirty(); ··· 265 277 if (tombstones.has(record.id)) continue; 266 278 267 279 // If this id was previously known but is absent from local, 268 - // it was deleted locally — skip it. 269 - if (knownIds.has(record.id) && !merged.has(record.id)) continue; 280 + // it was deleted locally — skip it. Only apply this heuristic when 281 + // localArr is non-empty; an empty localArr could mean the local cache 282 + // was cleared rather than the user deleting everything. 283 + if ( 284 + localArr.length > 0 && 285 + knownIds.has(record.id) && 286 + !merged.has(record.id) 287 + ) continue; 270 288 271 289 const existing = merged.get(record.id); 272 290