From 04eecede212a5b5cc9b03999e4cdfdfb14fcc866 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sat, 31 Aug 2013 18:52:29 -0400 Subject: [PATCH] Make query even more efficient. --- tasks/afc_statistics.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tasks/afc_statistics.py b/tasks/afc_statistics.py index 31926ab..0f34d00 100644 --- a/tasks/afc_statistics.py +++ b/tasks/afc_statistics.py @@ -232,26 +232,26 @@ class AFCStatistics(Task): query = """SELECT s.page_id, s.page_title, s.page_modify_oldid, r.page_latest, r.page_title, r.page_namespace FROM page AS s - LEFT JOIN {0}_p.page AS r ON s.page_id = r.page_id""" + LEFT JOIN {0}_p.page AS r ON s.page_id = r.page_id + WHERE s.page_modify_oldid != r.page_latest""" cursor.execute(query.format(self.site.name)) for pageid, title, oldid, real_oldid, real_title, real_ns in cursor: if not real_oldid: self.untrack_page(cursor, pageid) continue - if oldid != real_oldid: - msg = u"Updating page [[{0}]] (id: {1}) @ {2}" - self.logger.debug(msg.format(title, pageid, oldid)) - self.logger.debug(" {0} -> {1}".format(oldid, real_oldid)) - real_title = real_title.decode("utf8").replace("_", " ") - ns = self.site.namespace_id_to_name(real_ns) - if ns: - real_title = u":".join((ns, real_title)) - try: - self.update_page(cursor, pageid, real_title) - except Exception: - e = u"Error updating page [[{0}]] (id: {1})" - self.logger.exception(e.format(real_title, pageid)) + msg = u"Updating page [[{0}]] (id: {1}) @ {2}" + self.logger.debug(msg.format(title, pageid, oldid)) + self.logger.debug(" {0} -> {1}".format(oldid, real_oldid)) + real_title = real_title.decode("utf8").replace("_", " ") + ns = self.site.namespace_id_to_name(real_ns) + if ns: + real_title = u":".join((ns, real_title)) + try: + self.update_page(cursor, pageid, real_title) + except Exception: + e = u"Error updating page [[{0}]] (id: {1})" + self.logger.exception(e.format(real_title, pageid)) def add_untracked(self, cursor): """Add pending submissions that are not yet tracked.