feat: implement neue SRS-Logik zur Berechnung von Intervallen und füge Diagnoseskript für fällige Items hinzu
All checks were successful
Deploy to production / deploy (push) Successful in 2m10s
All checks were successful
Deploy to production / deploy (push) Successful in 2m10s
This commit is contained in:
47
backend/scripts/diag-srs-stats.js
Normal file
47
backend/scripts/diag-srs-stats.js
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env node
|
||||
import { sequelize } from '../utils/sequelize.js';
|
||||
|
||||
const run = async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('✅ DB connection OK');
|
||||
|
||||
const queries = {
|
||||
totalDue: `SELECT count(*)::int AS total_due FROM community.vocab_srs_item WHERE next_due_at <= now()`,
|
||||
byStage: `SELECT stage, count(*)::int AS cnt FROM community.vocab_srs_item WHERE next_due_at <= now() GROUP BY stage ORDER BY stage`,
|
||||
perDay30: `SELECT date(next_due_at) AS day, count(*)::int AS cnt FROM community.vocab_srs_item WHERE next_due_at <= now() GROUP BY day ORDER BY day DESC LIMIT 30`,
|
||||
createdToday: `SELECT count(*)::int AS created_today FROM community.vocab_srs_item WHERE date(created_at) = current_date`,
|
||||
recentNextDue: `SELECT item_key, course_id, stage, next_due_at, created_at FROM community.vocab_srs_item WHERE next_due_at > now() - interval '1 day' ORDER BY next_due_at ASC LIMIT 200`
|
||||
};
|
||||
|
||||
const [totalRes] = await sequelize.query(queries.totalDue, { type: sequelize.QueryTypes.SELECT });
|
||||
console.log('\nTotal due items: ', totalRes?.total_due ?? 'N/A');
|
||||
|
||||
const byStage = await sequelize.query(queries.byStage, { type: sequelize.QueryTypes.SELECT });
|
||||
console.log('\nDue by stage:');
|
||||
console.table(byStage);
|
||||
|
||||
const perDay = await sequelize.query(queries.perDay30, { type: sequelize.QueryTypes.SELECT });
|
||||
console.log('\nDue per day (last 30):');
|
||||
console.table(perDay);
|
||||
|
||||
const [createdRes] = await sequelize.query(queries.createdToday, { type: sequelize.QueryTypes.SELECT });
|
||||
console.log('\nCreated today: ', createdRes?.created_today ?? 'N/A');
|
||||
|
||||
const recent = await sequelize.query(queries.recentNextDue, { type: sequelize.QueryTypes.SELECT });
|
||||
console.log('\nExamples of items with next_due_at in the last 24h:');
|
||||
console.table(recent.slice(0, 50));
|
||||
|
||||
// Summary recommendation
|
||||
console.log('\nNotes:');
|
||||
console.log('- If many items are in stage 0/1 and created_today > 0, check code paths that call _ensureSrsItems.');
|
||||
console.log('- If many next_due_at are very recent, items may be created with next_due_at = now() causing large due counts.');
|
||||
} catch (err) {
|
||||
console.error('Error running diagnostics:', err);
|
||||
process.exitCode = 2;
|
||||
} finally {
|
||||
try { await sequelize.close(); } catch (_) {}
|
||||
}
|
||||
};
|
||||
|
||||
run();
|
||||
Reference in New Issue
Block a user