feat(mindspace): enforce PostgreSQL user data delivery

This commit is contained in:
john
2026-07-13 15:29:29 +08:00
parent b33c943b69
commit a6620fb719
57 changed files with 2779 additions and 164 deletions
+10 -5
View File
@@ -11,12 +11,16 @@ export function createPageSyncService({
} = {}) {
const syncInFlight = new Map();
async function syncUserGeneratedPages(userId) {
async function syncUserGeneratedPages(userId, { onlyRelativePaths = null } = {}) {
if (!pool || !pageService || !userId) {
return { created: 0, skipped: 0, updated: 0 };
}
let inFlight = syncInFlight.get(userId);
const scopeKey = onlyRelativePaths == null
? '*'
: [...new Set(onlyRelativePaths)].sort().join('|');
const inFlightKey = `${userId}:${scopeKey}`;
let inFlight = syncInFlight.get(inFlightKey);
if (!inFlight) {
inFlight = syncGeneratedPagesFromPublicAssets({
pool,
@@ -25,17 +29,18 @@ export function createPageSyncService({
userId,
publishDir: h5Root ? resolvePublishDir(h5Root, { id: userId }) : null,
syncWorkspaceAssets,
onlyRelativePaths,
})
.catch((error) => {
logger.warn?.('[MindSpace] page sync failed:', error?.message ?? error);
return { created: 0, skipped: 0, updated: 0 };
})
.finally(() => {
if (syncInFlight.get(userId) === inFlight) {
syncInFlight.delete(userId);
if (syncInFlight.get(inFlightKey) === inFlight) {
syncInFlight.delete(inFlightKey);
}
});
syncInFlight.set(userId, inFlight);
syncInFlight.set(inFlightKey, inFlight);
}
return inFlight;
}