1- const getDatabase = require ( './mongodb' ) ;
1+ const mongodb = require ( './mongodb' ) ;
22const config = require ( '../config' ) ;
33
44/**
@@ -7,15 +7,15 @@ const config = require('../config');
77 */
88async function setupLogRetention ( ) {
99 try {
10- const db = await getDatabase ( ) ;
10+ const db = mongodb . get ( 'rsscloud' ) ;
1111 const collection = db . collection ( 'events' ) ;
1212
1313 const retentionSeconds = config . logRetentionHours * 3600 ;
1414
15- // Create TTL index on the when field (log timestamp)
16- // MongoDB will automatically delete documents when 'when ' is older than retentionSeconds
15+ // Create TTL index on the time field (log timestamp)
16+ // MongoDB will automatically delete documents when 'time ' is older than retentionSeconds
1717 await collection . createIndex (
18- { when : 1 } ,
18+ { time : 1 } ,
1919 {
2020 expireAfterSeconds : retentionSeconds ,
2121 name : 'log_retention_ttl'
@@ -35,14 +35,14 @@ async function setupLogRetention() {
3535 */
3636async function removeExpiredLogs ( ) {
3737 try {
38- const db = await getDatabase ( ) ;
38+ const db = mongodb . get ( 'rsscloud' ) ;
3939 const collection = db . collection ( 'events' ) ;
4040
4141 const cutoffDate = new Date ( ) ;
4242 cutoffDate . setHours ( cutoffDate . getHours ( ) - config . logRetentionHours ) ;
4343
4444 const result = await collection . deleteMany ( {
45- when : { $lt : cutoffDate }
45+ time : { $lt : cutoffDate }
4646 } ) ;
4747
4848 console . log ( `Removed ${ result . deletedCount } expired log entries older than ${ cutoffDate . toISOString ( ) } ` ) ;
0 commit comments