Skip to content

Commit b5b5f35

Browse files
committed
Fix scheduled card duplication logic
1 parent 8028ce4 commit b5b5f35

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

server/card_scheduler.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,26 @@ def _process_schedule(self, db, schedule: ScheduledCard, now: datetime):
199199
# This prevents creating duplicate cards if the scheduler runs multiple times
200200
# within the lookback window (e.g., after a restart)
201201
if not schedule.allow_duplicates: # type: ignore
202-
# For non-duplicate schedules, check if any active cards exist from this schedule
202+
# Get the template card to check its column
203+
template = db.query(Card).filter(Card.id == schedule.card_id).first()
204+
if not template:
205+
logger.error(f"Template card {schedule.card_id} not found for schedule {schedule.id}")
206+
return
207+
208+
# For non-duplicate schedules, check if any active cards exist from this schedule IN THE SAME COLUMN
203209
# This is a simple but effective way to prevent duplicates without needing timestamps
204210
existing_card = (
205211
db.query(Card)
212+
.filter(Card.column_id == template.column_id) # Check same column only
206213
.filter(Card.schedule == schedule.id)
207214
.filter(Card.scheduled.is_(False)) # Don't count template cards
208215
.filter(Card.archived.is_(False)) # Only check active cards
209216
.first()
210217
)
211218

212219
if existing_card:
213-
# Already have an active card for this schedule, skip
214-
logger.debug(f"Skipping schedule {schedule.id} - active card already exists")
220+
# Already have an active card for this schedule in this column, skip
221+
logger.debug(f"Skipping schedule {schedule.id} - active card already exists in column {template.column_id}")
215222
return
216223

217224
logger.info(f"Creating card for schedule {schedule.id} (missed by {time_since_run:.0f} seconds)")

0 commit comments

Comments
 (0)