Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing library detached bug #179

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions biblib/views/library_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def process_solr(self, library, start, rows, sort, fl, session, add_sort):
)
if add_sort:

solr = self.timestamp_sort(solr, library.id, reverse=reverse)
solr = self.timestamp_sort(solr, library, reverse=reverse)

documents = [doc['bibcode'] for doc in solr['response']['docs']]
else:
Expand Down Expand Up @@ -447,7 +447,7 @@ def get_library_data(self, data):


@staticmethod
def timestamp_sort(solr, library_id, reverse=False):
def timestamp_sort(solr, library, reverse=False):
"""
Take a solr response and sort it based on the timestamps contained in the library
:input: response: response from SOLR bigquery
Expand All @@ -458,15 +458,12 @@ def timestamp_sort(solr, library_id, reverse=False):
"""
if "error" not in solr['response'].keys():
try:
with current_app.session_scope() as session:
# Find the specified library
library = session.query(Library).filter_by(id=library_id).one()
#First we generate a list of timestamps for the valid bibcodes
timestamp = [library.bibcode[doc['bibcode']]['timestamp'] for doc in solr['response']['docs']]
#Then we sort the SOLR response by the generated timestamp list
solr['response']['docs'] = [\
doc for (doc, timestamp) in sorted(zip(solr['response']['docs'], timestamp), reverse=reverse, key = lambda stamped: stamped[1])\
]
#First we generate a list of timestamps for the valid bibcodes
timestamp = [library.bibcode[doc['bibcode']]['timestamp'] for doc in solr['response']['docs']]
#Then we sort the SOLR response by the generated timestamp list
solr['response']['docs'] = [\
doc for (doc, timestamp) in sorted(zip(solr['response']['docs'], timestamp), reverse=reverse, key = lambda stamped: stamped[1])\
]
except Exception as e:
current_app.logger.warn("Failed to retrieve timestamps for {} with exception: {}. Returning default sorting.".format(library.id, e))
else:
Expand Down
Loading