Skip to content

Commit

Permalink
fix: Sort metadata entries by id desc (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
karatugo authored Apr 5, 2024
1 parent 857a58f commit f4505a3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sumstats_service/resources/mongo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ def get_study_metadata(self, study):
return meta_dict

def get_study_metadata_by_gcst(self, gcst):
meta_dict = self.study_collection.find_one({"gcst": gcst})
# meta_dict = self.study_collection.find_one({"gcst": gcst})
# Note that we use .find() rather than .find_one() as above. The reason
# is that there might exist multiple entries for a single gcst id, e.g.,
# when the template is edited. Therefore, here, we first get all, then
# sort by _id descending, get the last one (which should be the latest entry).
last_created_entry = self.study_collection.find({"gcst": gcst}).sort('_id', -1).limit(1)
meta_dict = next(last_created_entry, None)
return meta_dict

def update_retrieved_status(self, study, status):
Expand Down

0 comments on commit f4505a3

Please sign in to comment.