Skip to content

Commit

Permalink
sessions sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
niklastheman committed Oct 27, 2023
1 parent b4c21df commit 6f20a66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
11 changes: 5 additions & 6 deletions fedn/fedn/network/api/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,12 @@ def get_all_sessions(self, limit=None, skip=None):
jsonify({"success": False, "message": "No sessions found."}),
404,
)
payload = {}
for object in sessions_object["result"]:
id = object["session_id"]
info = object["session_config"][0]
payload[id] = info
arr = []
for element in sessions_object["result"]:
obj = element["session_config"][0]
arr.append(obj)

result = {"result": payload, "count": sessions_object["count"]}
result = {"result": arr, "count": sessions_object["count"]}

return jsonify(result)

Expand Down
10 changes: 7 additions & 3 deletions fedn/fedn/network/statestore/mongostatestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def transition(self, state):
)
)

def get_sessions(self, limit=None, skip=None):
def get_sessions(self, limit=None, skip=None, sort_key="_id", sort_order=pymongo.DESCENDING):
"""Get all sessions.
:return: All sessions.
Expand All @@ -124,9 +124,13 @@ def get_sessions(self, limit=None, skip=None):
limit = int(limit)
skip = int(skip)

result = self.sessions.find().limit(limit).skip(skip)
result = self.sessions.find().limit(limit).skip(skip).sort(
sort_key, sort_order
)
else:
result = self.sessions.find()
result = self.sessions.find().sort(
sort_key, sort_order
)

count = self.sessions.count_documents({})

Expand Down

0 comments on commit 6f20a66

Please sign in to comment.