Support the before query for user count and blender syc users

This commit is contained in:
2017-03-17 11:41:44 +01:00
parent 56b5c89edf
commit 28f9ec5ffa
2 changed files with 14 additions and 8 deletions

View File

@@ -41,12 +41,12 @@ def count_nodes(query=None) -> int:
return count
def count_users() -> int:
def count_users(query=None) -> int:
u = current_app.db()['users']
return u.count()
return u.count(query)
def count_blender_sync() -> int:
def count_blender_sync(query=None) -> int:
pipeline = [
# 0 Find all startups.blend that are not deleted
{
@@ -79,6 +79,10 @@ def count_blender_sync() -> int:
{'$count': 'tot'}
]
c = current_app.db()['nodes']
# If we provide a query, we extend the first $match step in the aggregation pipeline with
# with the extra parameters (for example _created)
if query:
pipeline[0]['$match'].update(query)
# Return either a list with one item or an empty list
r = list(c.aggregate(pipeline=pipeline))
count = 0 if not r else r[0]['tot']

View File

@@ -15,16 +15,18 @@ def get_stats(before: datetime.datetime):
query_comments = {'node_type': 'comment'}
query_assets = {'node_type': 'asset'}
date_query = {}
if before:
d = {'_created': {'$lt': before}}
query_comments.update(d)
query_assets.update(d)
date_query = {'_created': {'$lt': before}}
query_comments.update(date_query)
query_assets.update(date_query)
stats = {
'comments': count_nodes(query_comments),
'assets': count_nodes(query_assets),
'users_total': count_users(),
'users_blender_sync': count_blender_sync(),
'users_total': count_users(date_query),
'users_blender_sync': count_blender_sync(date_query),
}
return stats