Move actor_user parsing on the server side
This is done to prevent excessive load from clients requesting additional info for the actor_user right after they query for a list of notifications.
This commit is contained in:
parent
b495552ae4
commit
9bb95ab054
10
pillar/application/modules/users.py
Normal file
10
pillar/application/modules/users.py
Normal file
@ -0,0 +1,10 @@
|
||||
import hashlib
|
||||
import urllib
|
||||
|
||||
|
||||
def gravatar(email, size=64):
|
||||
parameters = {'s': str(size), 'd': 'mm'}
|
||||
return "https://www.gravatar.com/avatar/" + \
|
||||
hashlib.md5(str(email)).hexdigest() + \
|
||||
"?" + urllib.urlencode(parameters)
|
||||
|
@ -1,11 +1,10 @@
|
||||
from flask import g
|
||||
from eve.methods.post import post_internal
|
||||
from application import app
|
||||
from application.modules.users import gravatar
|
||||
|
||||
|
||||
def notification_parse(notification):
|
||||
# notification = dict(a='n')
|
||||
# TODO: finish fixing this
|
||||
activities_collection = app.data.driver.db['activities']
|
||||
activities_subscriptions_collection = \
|
||||
app.data.driver.db['activities-subscriptions']
|
||||
@ -53,9 +52,18 @@ def notification_parse(notification):
|
||||
else:
|
||||
is_subscribed = False
|
||||
|
||||
# Parse user_actor
|
||||
actor = users_collection.find_one({'_id': activity['actor_user']})
|
||||
if actor:
|
||||
parsed_actor = {
|
||||
'username': actor['username'],
|
||||
'avatar': gravatar(actor['email'])}
|
||||
else:
|
||||
parsed_actor = None
|
||||
|
||||
updates = dict(
|
||||
_id=notification['_id'],
|
||||
actor=activity['actor_user'],
|
||||
actor=parsed_actor,
|
||||
action=action,
|
||||
object_type=object_type,
|
||||
object_name=object_name,
|
||||
|
Loading…
x
Reference in New Issue
Block a user