From ed8751970fda88263fc3756b9a227aee9558c975 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sat, 19 Nov 2011 17:08:26 -0500 Subject: [PATCH] Fix update_date() when a submission is in multiple date categories. --- bot/tasks/afc_history.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/bot/tasks/afc_history.py b/bot/tasks/afc_history.py index 8224146..26996f4 100644 --- a/bot/tasks/afc_history.py +++ b/bot/tasks/afc_history.py @@ -93,29 +93,28 @@ class Task(BaseTask): msg = "Updating {0} ([[{1}]])".format(date, category.title()) self.logger.debug(msg) - q_select = "SELECT page_id, page_status FROM page WHERE page_date = ?" + q_select = "SELECT page_date, page_status FROM page WHERE page_id = ?" q_delete = "DELETE FROM page WHERE page_id = ?" - q_update = "UPDATE page SET page_status = ? WHERE page_id = ?" + q_update = "UPDATE page SET page_date = ?, page_status = ? WHERE page_id = ?" q_insert = "INSERT INTO page VALUES (?, ?, ?)" members = category.members(use_sql=True) - tracked = [] - statuses = {} with self.conn.cursor() as cursor: - cursor.execute(q_select, (date,)) - for pageid, status in cursor: - tracked.append(pageid) - statuses[pageid] = status - for title, pageid in members: + cursor.execute(q_select, (pageid,)) + stored = cursor.fetchall() status = self.get_status(title, pageid) + if status == STATUS_NONE: - if pageid in tracked: + if stored: cursor.execute(q_delete, (pageid,)) continue - if pageid in tracked: - if status != statuses[pageid]: - cursor.execute(q_update, (status, pageid)) + + if stored: + stored_date, stored_status = list(stored) + if date != stored_date or status != stored_status: + cursor.execute(q_update, (date, status, pageid)) + else: cursor.execute(q_insert, (pageid, date, status))