Улучшение fillCheckQueue

This commit is contained in:
Book Pauk
2022-07-28 20:22:38 +07:00
parent 18c8b2d803
commit 45ea26810a

View File

@@ -184,8 +184,8 @@ class BUCServer {
log(LM_WARN, `clean 'buc' table: deleted ${res.deleted}`); log(LM_WARN, `clean 'buc' table: deleted ${res.deleted}`);
} }
//rows = await db.select({table: 'buc', count: true}); rows = await db.select({table: 'buc', count: true});
//log(LM_WARN, `'buc' table length: ${rows[0].count}`); log(LM_WARN, `'buc' table size: ${rows[0].count}`);
now = Date.now(); now = Date.now();
//выборка кандидатов //выборка кандидатов
@@ -200,24 +200,30 @@ class BUCServer {
` `
}); });
//console.log(rows); //формирование checkQueue
if (rows.length) { if (rows.length) {
const ids = []; const ids = [];
const rowsToPush = [];
//сначала выберем сколько надо
for (const row of rows) { for (const row of rows) {
if (this.checkQueue.length >= this.maxCheckQueueLength) if (this.checkQueue.length + rowsToPush.length >= this.maxCheckQueueLength)
break; break;
rowsToPush.push(row);
ids.push(row.id); ids.push(row.id);
this.checkQueue.push(row);
} }
//установим у них флаг "в обработке"
await db.update({ await db.update({
table: 'buc', table: 'buc',
mod: `(r) => r.state = 1`, mod: `(r) => r.state = 1`,
where: `@@id(${db.esc(ids)})` where: `@@id(${db.esc(ids)})`
}); });
//пушим в очередь, после этого их обработает periodicCheck
for (const row of rowsToPush)
this.checkQueue.push(row);
log(LM_WARN, `checkQueue: added ${ids.length} recs, total ${this.checkQueue.length}`); log(LM_WARN, `checkQueue: added ${ids.length} recs, total ${this.checkQueue.length}`);
} }