From 3bc9344965eaa8915a371a741389936c7cd74e31 Mon Sep 17 00:00:00 2001 From: Andre D Date: Mon, 26 Nov 2012 11:14:23 -0500 Subject: [PATCH] wiki: Add author props in batch. --- r2/r2/models/wiki.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/r2/r2/models/wiki.py b/r2/r2/models/wiki.py index 51ebd433f..7ceea1dd0 100644 --- a/r2/r2/models/wiki.py +++ b/r2/r2/models/wiki.py @@ -89,16 +89,26 @@ class WikiRevision(tdb_cassandra.UuidThing, Printable): return Account._byID36(author) if author else None @classmethod - def add_props(cls, user, wrapped): + def get_authors(cls, revisions): + authors = [r._get('author') for r in revisions] + authors = filter(None, authors) + return Account._byID36(authors) + + @classmethod + def get_printable_authors(cls, revisions): from r2.lib.pages import WrappedUser + authors = cls.get_authors(revisions) + return dict([(v._id36, WrappedUser(v)) + for k, v in authors.items() if v]) + + @classmethod + def add_props(cls, user, wrapped): + authors = cls.get_printable_authors(wrapped) for item in wrapped: item._hidden = item.is_hidden item._spam = False - author = item.get_author() - if author is None: - item.printable_author = '[unknown]' - else: - item.printable_author = WrappedUser(author) + author = item._get('author') + item.printable_author = authors.get(author, '[unknown]') item.reported = False @classmethod