feat(mindspace): enforce PostgreSQL user data delivery
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user