Screen all older fallback candidates
This commit is contained in:
1 parent
83b5f1f5b6
commit
5c9839926d
2 files changed
+17
-23
No files matched your search
+11
-17
@@ -19,7 +19,6 @@ interface ListingScreeningSummary {
|
||||
eligible: number;
|
||||
outsideRecentWindow: number;
|
||||
deferred: number;
|
||||
deferredReason: 'selected-recent-candidate' | 'older-than-fallback' | null;
|
||||
}
|
||||
|
||||
/** Coordinates permanent polling disablement across account runtimes. */
|
||||
@@ -52,9 +51,10 @@ export class MonitorService {
|
||||
const recentCutoffSec = prioritizeRecent
|
||||
? Math.floor(Date.now() / 1000) - this.config.reddit.recentWindowMinutes * 60
|
||||
: 0;
|
||||
// Older posts found while prioritizing recent ones — used as a fallback
|
||||
// so the bot still has something to do if no recent posts exist anywhere.
|
||||
let fallback: RedditPost | null = null;
|
||||
// Older posts found while prioritizing recent ones. Screen every eligible
|
||||
// older candidate so seller and recipient filters are applied consistently,
|
||||
// then select the newest one only if no recent post exists anywhere.
|
||||
const fallbackCandidates: RedditPost[] = [];
|
||||
|
||||
for (const subreddit of subreddits) {
|
||||
try {
|
||||
@@ -70,7 +70,6 @@ export class MonitorService {
|
||||
eligible: 0,
|
||||
outsideRecentWindow: 0,
|
||||
deferred: 0,
|
||||
deferredReason: null,
|
||||
};
|
||||
let selected: RedditPost | null = null;
|
||||
|
||||
@@ -140,18 +139,15 @@ export class MonitorService {
|
||||
if (!prioritizeRecent || post.created_utc >= recentCutoffSec) {
|
||||
selected = post;
|
||||
summary.deferred = newestFirst.length - index - 1;
|
||||
summary.deferredReason = 'selected-recent-candidate';
|
||||
break;
|
||||
}
|
||||
|
||||
// This is the newest eligible post in this subreddit. Keep it as a
|
||||
// possible fallback, then move to the next subreddit to look for a
|
||||
// recent candidate. Older posts in this batch cannot improve it.
|
||||
// Keep every eligible older post. We deliberately finish screening
|
||||
// the listing rather than stopping at its newest fallback candidate:
|
||||
// later posts may be rejected, and this keeps the fallback decision
|
||||
// based on the full set of available posts.
|
||||
summary.outsideRecentWindow += 1;
|
||||
if (!fallback || post.created_utc > fallback.created_utc) fallback = post;
|
||||
summary.deferred = newestFirst.length - index - 1;
|
||||
summary.deferredReason = 'older-than-fallback';
|
||||
break;
|
||||
fallbackCandidates.push(post);
|
||||
}
|
||||
|
||||
this.logListingSummary(subreddit.name, posts.length, summary, selected !== null);
|
||||
@@ -179,6 +175,7 @@ export class MonitorService {
|
||||
}
|
||||
}
|
||||
|
||||
const fallback = fallbackCandidates.sort((a, b) => b.created_utc - a.created_utc)[0];
|
||||
if (fallback) {
|
||||
this.logger.info(
|
||||
`No posts within last ${this.config.reddit.recentWindowMinutes}m — falling back to newest available (r/${fallback.subreddit})`,
|
||||
@@ -259,10 +256,7 @@ export class MonitorService {
|
||||
`${summary.outsideRecentWindow} outside recent window`,
|
||||
];
|
||||
if (summary.deferred > 0) {
|
||||
const reason = summary.deferredReason === 'older-than-fallback'
|
||||
? 'older than eligible fallback'
|
||||
: 'not evaluated after selected recent candidate';
|
||||
counts.push(`${summary.deferred} ${reason}`);
|
||||
counts.push(`${summary.deferred} not evaluated after selected recent candidate`);
|
||||
}
|
||||
this.logger.info(`r/${subreddit} listing: ${counts.join('; ')}`);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user