feat: aktualisiere SRS-Logik zur Verwendung von konfigurierbaren Zeitfenstern für die Auswahl und Aktualisierung von Elementen
All checks were successful
Deploy to production / deploy (push) Successful in 2m9s
All checks were successful
Deploy to production / deploy (push) Successful in 2m9s
This commit is contained in:
@@ -10,20 +10,25 @@ import { sequelize } from '../utils/sequelize.js';
|
||||
*/
|
||||
|
||||
const DRY_RUN = process.env.DRY_RUN !== 'false';
|
||||
const LOOKBACK_DAYS = parseInt(process.env.LOOKBACK_DAYS || '365', 10);
|
||||
const WINDOW_SECONDS = parseInt(process.env.WINDOW_SECONDS || '10', 10);
|
||||
|
||||
const run = async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('✅ DB connection OK');
|
||||
|
||||
// Conservative selector: items created in the last 3 days where next_due_at is within 2 minutes of created_at
|
||||
// Selector: items created in the last LOOKBACK_DAYS where next_due_at is within WINDOW_SECONDS of created_at
|
||||
const selector = `
|
||||
SELECT id, item_key, course_id, stage, next_due_at, created_at
|
||||
FROM community.vocab_srs_item
|
||||
WHERE created_at >= now() - interval '3 days'
|
||||
AND abs(extract(epoch from (next_due_at - created_at))) < 120
|
||||
WHERE created_at >= now() - interval '${LOOKBACK_DAYS} days'
|
||||
AND (
|
||||
next_due_at = created_at
|
||||
OR abs(extract(epoch from (next_due_at - created_at))) <= ${WINDOW_SECONDS}
|
||||
)
|
||||
ORDER BY created_at ASC
|
||||
LIMIT 500
|
||||
LIMIT 1000
|
||||
`;
|
||||
|
||||
const recent = await sequelize.query(selector, { type: sequelize.QueryTypes.SELECT });
|
||||
@@ -31,7 +36,7 @@ const run = async () => {
|
||||
console.table(recent.slice(0, 20));
|
||||
|
||||
if (recent.length === 0) {
|
||||
console.log('\nNo candidate rows found — nothing to do.');
|
||||
console.log(`\nNo candidate rows found for lookback ${LOOKBACK_DAYS} days and window ${WINDOW_SECONDS}s — nothing to do.`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -40,8 +45,11 @@ const run = async () => {
|
||||
const updateQuery = `
|
||||
UPDATE community.vocab_srs_item
|
||||
SET next_due_at = date_trunc('day', created_at + interval '1 day') + interval '8 hours'
|
||||
WHERE created_at >= now() - interval '3 days'
|
||||
AND abs(extract(epoch from (next_due_at - created_at))) < 120
|
||||
WHERE created_at >= now() - interval '${LOOKBACK_DAYS} days'
|
||||
AND (
|
||||
next_due_at = created_at
|
||||
OR abs(extract(epoch from (next_due_at - created_at))) <= ${WINDOW_SECONDS}
|
||||
)
|
||||
RETURNING id, item_key, course_id, stage, next_due_at, created_at;
|
||||
`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user