fix: extend dupe guard window to 30 days by default
Weekly check was too narrow for bi-weekly and monthly campaigns. Parametric days= arg lets callers override for tighter schedules.
This commit is contained in:
parent
5f44ad66a5
commit
3407ebff66
1 changed files with 8 additions and 3 deletions
|
|
@ -310,11 +310,16 @@ class Store:
|
|||
self.conn.commit()
|
||||
return self._fetchone("SELECT * FROM posts WHERE id = ?", (post_id,))
|
||||
|
||||
def already_posted_this_week(self, campaign_id: int, target: str) -> bool:
|
||||
"""Return True if a successful post to this sub exists in the past 7 days."""
|
||||
def already_posted_this_week(self, campaign_id: int, target: str,
|
||||
days: int = 30) -> bool:
|
||||
"""Return True if a successful post to this sub exists within the past `days` days.
|
||||
|
||||
Default is 30 days — conservative enough to catch bi-weekly and monthly
|
||||
campaigns. Weekly campaigns should use max_posts instead of relying on this guard.
|
||||
"""
|
||||
row = self._fetchone(
|
||||
"SELECT id FROM posts WHERE campaign_id = ? AND target = ? AND status = 'success'"
|
||||
" AND posted_at >= datetime('now', '-7 days')",
|
||||
f" AND posted_at >= datetime('now', '-{days} days')",
|
||||
(campaign_id, target),
|
||||
)
|
||||
return row is not None
|
||||
|
|
|
|||
Loading…
Reference in a new issue