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

Configure Feed

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

fix: improve atproto tombstone handling

+25 -19
+25 -19
src/components/transformer/output/raw/atproto-sync/element.js
··· 63 63 const l = local(); 64 64 if (!l) return; 65 65 66 - // Track deletions: any id present in local but absent in 67 - // newData has been deleted by the user. 66 + const newIds = new Set(newData.map((/** @type {any} */ r) => r.id)); 67 + 68 + // Update tombstones in one pass: add for records deleted from local, 69 + // remove for records being (re-)added — so that fixed-ID records can 70 + // be recreated after deletion without the tombstone blocking them. 71 + const tombstones = this.#getTombstones(name); 72 + let tombstonesChanged = false; 73 + 68 74 const oldCol = await Output.data(l[name]); 69 75 if (oldCol && Array.isArray(oldCol.data)) { 70 - const newIds = new Set(newData.map((/** @type {any} */ r) => r.id)); 71 - 72 76 for (const record of oldCol.data) { 73 - if (!newIds.has(record.id)) { 74 - this.#addTombstone(name, record.id); 77 + if (!newIds.has(record.id) && !tombstones.has(record.id)) { 78 + tombstones.add(record.id); 79 + tombstonesChanged = true; 75 80 } 76 81 } 82 + } 83 + 84 + for (const record of newData) { 85 + if (tombstones.has(record.id)) { 86 + tombstones.delete(record.id); 87 + tombstonesChanged = true; 88 + } 89 + } 90 + 91 + if (tombstonesChanged) { 92 + localStorage.setItem( 93 + `${STORAGE_PREFIX}/tombstones/${name}`, 94 + JSON.stringify([...tombstones]), 95 + ); 77 96 } 78 97 79 98 // Update known ids ··· 271 290 `${STORAGE_PREFIX}/tombstones/${collection}`, 272 291 ); 273 292 return raw ? new Set(JSON.parse(raw)) : new Set(); 274 - } 275 - 276 - /** 277 - * @param {string} collection 278 - * @param {string} id 279 - */ 280 - #addTombstone(collection, id) { 281 - const tombstones = this.#getTombstones(collection); 282 - tombstones.add(id); 283 - localStorage.setItem( 284 - `${STORAGE_PREFIX}/tombstones/${collection}`, 285 - JSON.stringify([...tombstones]), 286 - ); 287 293 } 288 294 289 295 /**