Changeset 14f54a7 in Klonkt for src/services
- Timestamp:
- 07/04/2026 05:31:45 PM (2 months ago)
- Branches:
- main
- Children:
- 6ec0433
- Parents:
- 6dd1a3f
- File:
-
- 1 edited
-
src/services/ActivityPubService.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/services/ActivityPubService.js
r6dd1a3f r14f54a7 1878 1878 // during a flux window, e.g. a fleet-wide update), and drops notes that are gone 1879 1879 // (404/410). Bump SELFHEAL_VERSION only on a release that warrants a re-sync. 1880 const SELFHEAL_VERSION = 6; // v6: re-fetch so boosted notes cached coverless (pre image-fallback in resolveRemoteNote) pick up their cover1880 const SELFHEAL_VERSION = 7; // v7: rerun v6 with retry-until-clean semantics (origins briefly offline no longer stay stale forever) 1881 1881 async function fetchNoteAP(url) { 1882 1882 try { … … 2052 2052 let rows = []; 2053 2053 try { rows = db.prepare('SELECT id, content, media_json, nsfw, cw, url FROM ap_timeline ORDER BY rowid DESC LIMIT 200').all(); } catch { /* no table */ } 2054 let healed = 0 ;2054 let healed = 0, failed = 0; 2055 2055 for (const r of rows) { 2056 2056 try { 2057 2057 const note = await fetchNoteAP(r.id); 2058 2058 if (note === 404) { db.prepare('DELETE FROM ap_timeline WHERE id = ?').run(r.id); healed++; continue; } 2059 if (!note || typeof note !== 'object') continue;2059 if (!note || typeof note !== 'object') { failed++; continue; } // origin unreachable right now 2060 2060 const html = HtmlSanitizerService.sanitize(note.content || ''); 2061 2061 const media = mediaFromNote(note); … … 2067 2067 healed++; 2068 2068 } 2069 } catch { /* per-note best-effort */ } 2070 } 2071 try { db.prepare('INSERT OR REPLACE INTO app_settings (key, value) VALUES (?, ?)').run('selfheal_version', String(SELFHEAL_VERSION)); } catch { /* ignore */ } 2072 if (rows.length) console.log(`[AP] self-heal v${SELFHEAL_VERSION}: ${healed}/${rows.length} timeline notes`); 2069 } catch { failed++; /* per-note best-effort */ } 2070 } 2071 // Only mark this version DONE after a clean pass. Some origins are briefly 2072 // offline exactly when we heal (phone-hosted instances!): skipping them and 2073 // consuming the version would leave those rows stale forever. Instead retry 2074 // on the next boots, giving up after a few attempts (permanently-dead 2075 // origins answer 404/410 and are deleted above, so they don't loop). 2076 const setSetting = (k, v) => { try { db.prepare('INSERT OR REPLACE INTO app_settings (key, value) VALUES (?, ?)').run(k, String(v)); } catch { /* ignore */ } }; 2077 let attempts = 0; 2078 try { const a = db.prepare('SELECT value FROM app_settings WHERE key = ?').get('selfheal_attempts'); attempts = a ? (parseInt(a.value, 10) || 0) : 0; } catch { /* ignore */ } 2079 if (failed === 0 || attempts >= 4) { 2080 setSetting('selfheal_version', SELFHEAL_VERSION); 2081 setSetting('selfheal_attempts', 0); 2082 } else { 2083 setSetting('selfheal_attempts', attempts + 1); 2084 } 2085 if (rows.length) console.log(`[AP] self-heal v${SELFHEAL_VERSION}: ${healed}/${rows.length} timeline notes${failed ? ` (${failed} unreachable — will retry next boot)` : ''}`); 2073 2086 } catch { /* never block boot */ } finally { _selfHealing = false; } 2074 2087 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)