diff options
Diffstat (limited to 'sphinx/websupport/storage/sqlalchemystorage.py')
-rw-r--r-- | sphinx/websupport/storage/sqlalchemystorage.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/sphinx/websupport/storage/sqlalchemystorage.py b/sphinx/websupport/storage/sqlalchemystorage.py index 94318a965..1aaa84738 100644 --- a/sphinx/websupport/storage/sqlalchemystorage.py +++ b/sphinx/websupport/storage/sqlalchemystorage.py @@ -12,6 +12,7 @@ from datetime import datetime from sqlalchemy.orm import aliased +from sqlalchemy.sql import func from sphinx.websupport.errors import * from sphinx.websupport.storage import StorageBackend @@ -84,6 +85,19 @@ class SQLAlchemyStorage(StorageBackend): session.close() raise UserNotAuthorizedError() + def get_metadata(self, docname, moderator): + session = Session() + subquery = session.query( + Comment.id, Comment.node_id, + func.count('*').label('comment_count')).group_by( + Comment.node_id).subquery() + nodes = session.query(Node.id, subquery.c.comment_count).outerjoin( + (subquery, Node.id==subquery.c.node_id)).filter( + Node.document==docname) + session.close() + session.commit() + return dict([(k, v or 0) for k, v in nodes]) + def get_data(self, node_id, username, moderator): session = Session() node = session.query(Node).filter(Node.id == node_id).one() |