mirror of
https://github.com/fosrl/pangolin.git
synced 2026-07-06 04:10:13 +00:00
Batch get olm ids
This commit is contained in:
@@ -629,6 +629,21 @@ async function handleMessagesForSiteClients(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Batch-fetch all olm IDs for the clients we need to process
|
||||||
|
const clientIdsToProcess = Array.from(clientsToProcess.keys());
|
||||||
|
const olmRows =
|
||||||
|
clientIdsToProcess.length > 0
|
||||||
|
? await trx
|
||||||
|
.select({ olmId: olms.olmId, clientId: olms.clientId })
|
||||||
|
.from(olms)
|
||||||
|
.where(inArray(olms.clientId, clientIdsToProcess))
|
||||||
|
: [];
|
||||||
|
const olmByClientId = new Map<number, string>(
|
||||||
|
olmRows
|
||||||
|
.filter((r) => r.clientId !== null)
|
||||||
|
.map((r) => [r.clientId as number, r.olmId])
|
||||||
|
);
|
||||||
|
|
||||||
for (const client of clientsToProcess.values()) {
|
for (const client of clientsToProcess.values()) {
|
||||||
// UPDATE THE NEWT
|
// UPDATE THE NEWT
|
||||||
if (!client.subnet || !client.pubKey) {
|
if (!client.subnet || !client.pubKey) {
|
||||||
@@ -645,14 +660,8 @@ async function handleMessagesForSiteClients(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [olm] = await trx
|
const olmId = olmByClientId.get(client.clientId);
|
||||||
.select({
|
if (!olmId) {
|
||||||
olmId: olms.olmId
|
|
||||||
})
|
|
||||||
.from(olms)
|
|
||||||
.where(eq(olms.clientId, client.clientId))
|
|
||||||
.limit(1);
|
|
||||||
if (!olm) {
|
|
||||||
logger.warn(
|
logger.warn(
|
||||||
`Olm not found for client ${client.clientId} so cannot add/delete peers`
|
`Olm not found for client ${client.clientId} so cannot add/delete peers`
|
||||||
);
|
);
|
||||||
@@ -669,7 +678,7 @@ async function handleMessagesForSiteClients(
|
|||||||
clientId: client.clientId,
|
clientId: client.clientId,
|
||||||
siteId,
|
siteId,
|
||||||
publicKey: site.publicKey,
|
publicKey: site.publicKey,
|
||||||
olmId: olm.olmId
|
olmId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -691,7 +700,7 @@ async function handleMessagesForSiteClients(
|
|||||||
endpoint: exitNode.endpoint
|
endpoint: exitNode.endpoint
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
olmId: olm.olmId
|
olmId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user