Avoid scanning operation history on agent polls
This commit is contained in:
@@ -522,11 +522,14 @@ export function pendingHostOperationRows(hostId: string, lane: OperationLane = '
|
||||
.all(hostId, Number(host.readiness === 'ready' || host.mode === 'draining'), Number(host.inventory.capabilities?.includes('instance.cancel-create') ?? false),
|
||||
...(lane === 'health' ? [new Date(Date.now() - 30_000).toISOString()] : [])) as OperationDeliveryRow[];
|
||||
const preparationLimit = fleetSettings().preparationConcurrency;
|
||||
const preparing = new Set((database().prepare(`SELECT DISTINCT host_id FROM ec_host_operations
|
||||
WHERE kind IN ('library.download','library.import') AND last_delivered_at IS NOT NULL
|
||||
AND state IN ('pending','accepted','running','unknown')`).all() as { host_id: string }[]).map(row => row.host_id));
|
||||
const libraryKinds = ['library.download','library.import'];
|
||||
const preparing = preparationLimit && rows.some(operation => libraryKinds.includes(operation.kind))
|
||||
? new Set((database().prepare(`SELECT DISTINCT host_id FROM ec_host_operations
|
||||
WHERE kind IN ('library.download','library.import') AND last_delivered_at IS NOT NULL
|
||||
AND state IN ('pending','accepted','running','unknown')`).all() as { host_id: string }[]).map(row => row.host_id))
|
||||
: new Set<string>();
|
||||
const admitted = rows.filter(operation => {
|
||||
if (!['library.download','library.import'].includes(operation.kind) || preparing.has(hostId) || !preparationLimit) return true;
|
||||
if (!libraryKinds.includes(operation.kind) || preparing.has(hostId) || !preparationLimit) return true;
|
||||
if (preparing.size >= preparationLimit) return false;
|
||||
preparing.add(hostId); return true;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user