server/users: reduce user fields footprint

This commit is contained in:
rr-
2016-06-03 20:10:25 +02:00
parent 9d6878a1aa
commit 805ca845e3
5 changed files with 20 additions and 8 deletions

View File

@ -10,7 +10,7 @@ def serialize_comment(comment, authenticated_user, options=None):
comment,
{
'id': lambda: comment.comment_id,
'user': lambda: users.serialize_user(comment.user, authenticated_user),
'user': lambda: users.serialize_micro_user(comment.user),
'postId': lambda: comment.post.post_id,
'text': lambda: comment.text,
'creationTime': lambda: comment.creation_time,

View File

@ -81,7 +81,7 @@ def serialize_post(post, authenticated_user, options=None):
'flags': lambda: post.flags,
'tags': lambda: [tag.names[0].name for tag in post.tags],
'relations': lambda: [rel.post_id for rel in post.relations],
'user': lambda: users.serialize_user(post.user, authenticated_user),
'user': lambda: users.serialize_micro_user(post.user),
'score': lambda: post.score,
'ownScore': lambda: scores.get_score(post, authenticated_user),
'tagCount': lambda: post.tag_count,
@ -91,7 +91,7 @@ def serialize_post(post, authenticated_user, options=None):
'featureCount': lambda: post.feature_count,
'lastFeatureTime': lambda: post.last_feature_time,
'favoritedBy': lambda: [
users.serialize_user(rel.user, authenticated_user) \
users.serialize_micro_user(rel.user) \
for rel in post.favorited_by],
'hasCustomThumbnail':
lambda: files.has(get_post_thumbnail_backup_path(post)),

View File

@ -42,6 +42,12 @@ def serialize_user(user, authenticated_user, options=None, force_show_email=Fals
},
options)
def serialize_micro_user(user):
return serialize_user(
user,
authenticated_user=None,
options=['name', 'avatarUrl'])
def get_user_count():
return db.session.query(db.User).count()

View File

@ -68,10 +68,10 @@ def test_serialize_post(
post_factory, user_factory, comment_factory, tag_factory, config_injector):
config_injector({'data_url': 'http://example.com/'})
with unittest.mock.patch('szurubooru.func.comments.serialize_comment'), \
unittest.mock.patch('szurubooru.func.users.serialize_user'), \
unittest.mock.patch('szurubooru.func.users.serialize_micro_user'), \
unittest.mock.patch('szurubooru.func.posts.files.has', return_value=True), \
unittest.mock.patch('szurubooru.func.snapshots.get_serialized_history'):
users.serialize_user.side_effect = lambda user, auth_user: user.name
users.serialize_micro_user.side_effect = lambda user: user.name
comments.serialize_comment.side_effect \
= lambda comment, auth_user: comment.user.name
snapshots.get_serialized_history.return_value = 'snapshot history'