refactor(federation-worker): extract buildContextMapForPeer helper
Pure refactor — will be reused by the needs_attention transition handler. No behavior change.
This commit is contained in:
@@ -396,22 +396,7 @@ async function resolvePendingPeers(): Promise<void> {
|
|||||||
case 'rejected': {
|
case 'rejected': {
|
||||||
console.warn(`[federation-worker] Auto-peering rejected by ${peerOrigin}: ${result.error}`);
|
console.warn(`[federation-worker] Auto-peering rejected by ${peerOrigin}: ${result.error}`);
|
||||||
|
|
||||||
// Collect affected contexts before purging
|
const contextMap = buildContextMapForPeer(db, peerId);
|
||||||
const entries = db
|
|
||||||
.select({
|
|
||||||
contextId: schema.federationOutbox.contextId,
|
|
||||||
contextType: schema.federationOutbox.contextType,
|
|
||||||
})
|
|
||||||
.from(schema.federationOutbox)
|
|
||||||
.where(eq(schema.federationOutbox.peerId, peerId))
|
|
||||||
.all();
|
|
||||||
|
|
||||||
const contextMap = new Map<string, string>();
|
|
||||||
for (const e of entries) {
|
|
||||||
if (!contextMap.has(e.contextId)) {
|
|
||||||
contextMap.set(e.contextId, e.contextType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Purge outbox entries (NOT mutation log)
|
// Purge outbox entries (NOT mutation log)
|
||||||
db.delete(schema.federationOutbox)
|
db.delete(schema.federationOutbox)
|
||||||
@@ -433,6 +418,34 @@ async function resolvePendingPeers(): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a map of contextId → contextType for all outbox entries targeting
|
||||||
|
* a specific peer. Used for surfacing "delivery impossible" via
|
||||||
|
* pushPeerRejectedEvent when a peer is rejected or transitioned to
|
||||||
|
* needs_attention.
|
||||||
|
*/
|
||||||
|
function buildContextMapForPeer(
|
||||||
|
db: ReturnType<typeof getDb>,
|
||||||
|
peerId: string,
|
||||||
|
): Map<string, string> {
|
||||||
|
const entries = db
|
||||||
|
.select({
|
||||||
|
contextId: schema.federationOutbox.contextId,
|
||||||
|
contextType: schema.federationOutbox.contextType,
|
||||||
|
})
|
||||||
|
.from(schema.federationOutbox)
|
||||||
|
.where(eq(schema.federationOutbox.peerId, peerId))
|
||||||
|
.all();
|
||||||
|
|
||||||
|
const contextMap = new Map<string, string>();
|
||||||
|
for (const e of entries) {
|
||||||
|
if (!contextMap.has(e.contextId)) {
|
||||||
|
contextMap.set(e.contextId, e.contextType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return contextMap;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Push a federation_peer_rejected WS event to all local users affected by
|
* Push a federation_peer_rejected WS event to all local users affected by
|
||||||
* the rejection. Resolves contextLabel from the database for each context.
|
* the rejection. Resolves contextLabel from the database for each context.
|
||||||
|
|||||||
Reference in New Issue
Block a user