Admin > Email an update loads at once; audience counts fill in from the background
The panel waited on a Sendy pass over every member (minutes, and the cache empties on each deploy), so it showed blank. Counts are now a snapshot with a background refresh, and the form no longer depends on them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
+7
-1
@@ -36,6 +36,12 @@ async function recipients(kind) {
|
||||
return out;
|
||||
}
|
||||
async function counts() { const o = {}; for (const k of Object.keys(AUDIENCES)) o[k] = (await recipients(k)).length; return o; }
|
||||
// The admin panel must never wait on a count: one pass asks Sendy about every member with a pause between
|
||||
// each (minutes), and the in-memory cache starts empty after every deploy. The panel gets the last known
|
||||
// counts at once (or none) and a refresh runs in the background (Marty, 2026-09-28: the panel showed empty).
|
||||
let countsSnap = null, counting = false;
|
||||
async function refreshCounts() { if (counting) return; counting = true; try { countsSnap = await counts(); } catch (e) {} finally { counting = false; } }
|
||||
function countsSnapshot() { if (!countsSnap && !counting) refreshCounts().catch(() => {}); return countsSnap; }
|
||||
|
||||
function compose({ subject, intro, noteIds, closing }, acct) {
|
||||
const notes = R.releases.notes().filter(n => noteIds.includes(n.id));
|
||||
@@ -93,4 +99,4 @@ function draft() { try { return JSON.parse(fs.readFileSync(DRAFT(), 'utf8')); }
|
||||
function saveDraft(d) { const v = { subject: String(d.subject || '').slice(0, 150), intro: String(d.intro || '').slice(0, 8000), closing: String(d.closing || '').slice(0, 2000), noteIds: (d.noteIds || []).map(String).slice(0, 40), audience: AUDIENCES[d.audience] ? d.audience : 'optin', savedAt: Date.now() }; try { fs.writeFileSync(DRAFT(), JSON.stringify(v)); } catch (e) {} return v; }
|
||||
function status() { const l = log(); if (running) { const k = l.sends.find(x => x.id === running.id); if (k) Object.assign(k, running); } return { sends: l.sends.slice(0, 12), running: !!running }; }
|
||||
function lastSentAt() { const l = log(); const d = l.sends.find(x => x.status === 'done'); return d ? d.ts : 0; }
|
||||
module.exports = { init, AUDIENCES, counts, compose, send, status, lastSentAt, draft, saveDraft };
|
||||
module.exports = { init, AUDIENCES, counts, countsSnapshot, compose, send, status, lastSentAt, draft, saveDraft };
|
||||
|
||||
Reference in New Issue
Block a user