Events 3.7.2 + Website 1.6.1: no duplicate events after a reseed; "Events site" in the header
A reseed gives every event a new id without listing the old ones in the feed's `deleted`, and consumers only fetched ?updatedSince= after the first sync, so the old copies stayed beside the new ones. - Both: the 15-minute feed poll and "Sync now" fetch the whole list and drop copies that aren't in it; the fetch after event.changed stays incremental. - Events set-demo.js keeps FeedEntry and marks its live entries removed, resets the links' lastGoodAt, then publishes the new feed, sends event.changed and fetches the linked products' events back in. - Website loadDemo lists the old published events in FeedRemoval and sends event.changed after publishing. - Website header: links to the church's other sites read "Events site" with an external-link icon, not a second "Events". Checked: Website backend tests (133), Events backend tests (802), both typechecks, Website frontend build. set-demo.js not run end to end (no local database). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -179,7 +179,7 @@ export function adminRouter(ctx: Ctx) {
|
||||
r.post('/links/:id/sync', editor, handle(async (req) => {
|
||||
const link = await ctx.db.productLink.findUnique({ where: { installId: param(req, 'id') } });
|
||||
if (!link) throw new ApiError(404, 'NOT_LINKED', "That product isn't connected.");
|
||||
return syncLink(ctx, link);
|
||||
return syncLink(ctx, link, { full: true });
|
||||
}));
|
||||
r.put('/feed', editor, json, handle(async (req) => {
|
||||
await ctx.settings.set('feed_publish', req.body?.publish === false ? 'false' : 'true');
|
||||
|
||||
@@ -18,6 +18,7 @@ import { fileURLToPath } from 'node:url';
|
||||
import { CHURCH_SCHEMA, WEBSITE_TEMPLATES, type agent, type Church, type WebsiteTemplate } from '@crosscode/contracts';
|
||||
import type { Ctx } from '../context.js';
|
||||
import { churchProfile } from '../church/profile.js';
|
||||
import { markRemoved, notifyLinks } from '../feed/feed.js';
|
||||
import type { SectionData } from '../site/sections.js';
|
||||
import { publish } from '../site/snapshot.js';
|
||||
import { TEMPLATE_HEADERS, TEMPLATE_VARIANTS, SECTION_TYPES, defaultDesign, type SiteDesign } from '../site/variants.js';
|
||||
@@ -248,6 +249,10 @@ export async function loadDemo(ctx: Ctx, what: WebsiteTemplate | agent.WebsiteDe
|
||||
|
||||
// The site icon is a setting, so its picture stays; every other picture goes with the content.
|
||||
const faviconId = classic ? null : await ctx.settings.get('favicon_media_id');
|
||||
// 1.6.1: the published events that go are listed in the feed's `deleted`, so linked products
|
||||
// (Cross Events) drop their copies instead of showing them beside the new ones.
|
||||
const gone = (await db.simpleEvent.findMany({ where: { publishedAt: { not: null } }, select: { id: true } })).map((e) => e.id);
|
||||
for (const id of gone) await markRemoved(ctx, id, true);
|
||||
for (const m of ['section', 'page', 'ministry', 'leader', 'message', 'messageSeries', 'simpleEvent', 'siteVersion', 'siteDesign', 'slugHistory', 'previewLink'] as const) {
|
||||
await (db[m] as unknown as { deleteMany: (a?: object) => Promise<unknown> }).deleteMany({});
|
||||
}
|
||||
@@ -324,9 +329,13 @@ export async function loadDemo(ctx: Ctx, what: WebsiteTemplate | agent.WebsiteDe
|
||||
await db.message.create({ data: { slug, title, date: new Date(now.getTime() - ago * day), source: 'youtube', mediaUrl: 'https://www.youtube.com/watch?v=aqz-KE-bpKQ', thumbnailUrl, speaker, passage, seriesId: series.id, publishedAt: now } });
|
||||
}
|
||||
n = 0;
|
||||
const made: string[] = [];
|
||||
for (const [slug, title, inDays, description] of seed.events) {
|
||||
const startsAt = new Date(Math.floor((now.getTime() + inDays * day) / day) * day + 8 * 3600e3);
|
||||
await db.simpleEvent.create({ data: { slug, title, startsAt, endsAt: new Date(startsAt.getTime() + 3 * 3600e3), location: t(seed.venue), description: t(description), imageId: img[`event${n++}`] ?? null, publishedAt: now } });
|
||||
made.push((await db.simpleEvent.create({ data: { slug, title, startsAt, endsAt: new Date(startsAt.getTime() + 3 * 3600e3), location: t(seed.venue), description: t(description), imageId: img[`event${n++}`] ?? null, publishedAt: now } })).id);
|
||||
}
|
||||
return publish(ctx, { id: opts.publishedBy ?? 'demo', role: 'system' }, classic ? `Demo church on ${seed.template}` : `Demo: ${seed.label}`);
|
||||
const version = await publish(ctx, { id: opts.publishedBy ?? 'demo', role: 'system' }, classic ? `Demo church on ${seed.template}` : `Demo: ${seed.label}`);
|
||||
// Linked products fetch the feed now, not at their next poll (one try; the poll catches up).
|
||||
await notifyLinks(ctx, [...gone, ...made]).catch(() => {});
|
||||
return version;
|
||||
}
|
||||
|
||||
@@ -113,15 +113,19 @@ type LinkRow = { installId: string; product: string; url: string; showEvents: bo
|
||||
|
||||
export type SyncResult = { installId: string; ok: boolean; imported?: number; deleted?: number; rejected?: number; error?: string };
|
||||
|
||||
/** Fetches one sibling's feed into read-only copies. */
|
||||
export async function syncLink(ctx: Ctx, link: LinkRow): Promise<SyncResult> {
|
||||
/**
|
||||
* Fetches one sibling's feed into read-only copies. `full` asks for the whole list and drops copies
|
||||
* no longer in it: a sibling that loses events without listing them in `deleted` (a reseed, a
|
||||
* restore) would otherwise leave stale copies beside the new ones for good.
|
||||
*/
|
||||
export async function syncLink(ctx: Ctx, link: LinkRow, { full = false }: { full?: boolean } = {}): Promise<SyncResult> {
|
||||
if (link.product === 'accounts') return { installId: link.installId, ok: true, imported: 0 };
|
||||
if (!link.showEvents) {
|
||||
const gone = (await ctx.db.importedEvent.deleteMany({ where: { linkId: link.installId } })).count;
|
||||
return { installId: link.installId, ok: true, imported: 0, deleted: gone };
|
||||
}
|
||||
const now = ctx.now();
|
||||
const since = link.lastGoodAt ? new Date(link.lastGoodAt.getTime() - OVERLAP_MS) : null;
|
||||
const since = !full && link.lastGoodAt ? new Date(link.lastGoodAt.getTime() - OVERLAP_MS) : null;
|
||||
try {
|
||||
const url = await siblingUrl(ctx, link.url, FEED_PATHS.events);
|
||||
if (since) url.searchParams.set('updatedSince', since.toISOString());
|
||||
@@ -153,11 +157,11 @@ export async function syncLink(ctx: Ctx, link: LinkRow): Promise<SyncResult> {
|
||||
}
|
||||
}
|
||||
|
||||
/** Every linked sibling, one after another; one failing never stops the rest. */
|
||||
/** Every linked sibling's whole list, one after another; one failing never stops the rest. */
|
||||
export async function syncAll(ctx: Ctx) {
|
||||
const links = await ctx.db.productLink.findMany({ where: { product: { not: 'accounts' } } });
|
||||
let failed = 0;
|
||||
for (const link of links) if (!(await syncLink(ctx, link)).ok) failed++;
|
||||
for (const link of links) if (!(await syncLink(ctx, link, { full: true })).ok) failed++;
|
||||
return { links: links.length, failed };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user