From 55593a65429691b21e6f60932ade2bda7ac994bc Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Thu, 2 Jul 2015 23:52:22 +0300 Subject: [PATCH] copying an object instead of re-requesting from db --- SE_API/MessageRoutes.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/SE_API/MessageRoutes.py b/SE_API/MessageRoutes.py index a360da7..5942b85 100644 --- a/SE_API/MessageRoutes.py +++ b/SE_API/MessageRoutes.py @@ -1,3 +1,5 @@ +import copy + __author__ = 'Aran' from flask import Blueprint @@ -245,9 +247,11 @@ def getAllUserMessages(token): arr = [] - query = Message.all() - query.filter('isProject =', False) - for m in query.run(): + allMsgs = Message.all() + projectMsgs = copy.deepcopy(allMsgs) + + projectMsgs.filter('isProject =', False) + for m in projectMsgs.run(): if str(m.groupId) in user.courses_id_list: msgDic = dict(json.loads(m.to_JSON())) #add a key 'forSortDate' for sorting dates @@ -255,9 +259,9 @@ def getAllUserMessages(token): msgDic['forSortDate'] = msgTime arr.append(msgDic) - query = Message.all() - query.filter('isProject =', True) - for m in query.run(): + + allMsgs.filter('isProject =', True) + for m in allMsgs.run(): if str(m.groupId) in user.projects_id_list: msgDic = dict(json.loads(m.to_JSON())) #add a key 'forSortDate' for sorting dates