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

Missing timestamps #181

Merged
merged 5 commits into from
Apr 26, 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
26 changes: 15 additions & 11 deletions biblib/views/library_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def update_notes(cls, session, library, updated_list):
for updated_bibcode in updated_list:
for key, value in updated_bibcode.items():
updated_dict[key] = value

for note in notes:

if note.bibcode in updated_dict:
Expand Down Expand Up @@ -102,7 +103,7 @@ def update_notes(cls, session, library, updated_list):
return updated_notes

@classmethod
def update_database(cls, session, library, new_library_bibcodes, updates):
def update_library(cls, session, library):
"""
Carries the actual database update for the library and notes tables.
:param session: Necessary for the updates
Expand All @@ -117,14 +118,13 @@ def update_database(cls, session, library, new_library_bibcodes, updates):
updated_notes: list of notes that were updates
"""
try:
library.bibcode = new_library_bibcodes

session.add(library)
flag_modified(library, "bibcode")
session.commit()

updates['updated_notes'] = cls.update_notes(session, library, updates['update_list'])
except Exception as error:
current_app.logger.warning('Could not update database: {0}'
current_app.logger.warning('Could not update library: {0}'
.format(error))

@classmethod
Expand Down Expand Up @@ -152,15 +152,16 @@ def solr_update_library(cls, library_id, solr_docs, session):
)
# Extract the canonical bibcodes and create a hashmap
# in which the alternate bibcode is the key and the canonical bibcode is the value
alternate_bibcodes = cls.get_alternate_bibcodes(solr_docs)
alternate_bibcodes = cls.get_alternate_bibcodes(solr_docs) # alternate_bibcode: canonical_bibcode

library = session.query(Library).filter(Library.id == library_id).one()
default_timestamp = datetime.timestamp(library.date_created)

updated_timestamp = False
for bibcode in library.bibcode:

if "timestamp" not in library.bibcode[bibcode].keys():
library.bibcode[bibcode]["timestamp"] = default_timestamp
updated_timestamp = True

# Update if its an alternate
if bibcode in alternate_bibcodes:
Expand All @@ -175,11 +176,14 @@ def solr_update_library(cls, library_id, solr_docs, session):
updates['duplicates_removed'] += 1
else:
new_library_bibcodes[bibcode] = library.bibcode[bibcode]
session.add(library)
session.commit()
if updates['update_list']:
cls.update_database(session, library, new_library_bibcodes, updates)


if updates['update_list']:
library.bibcode = new_library_bibcodes
cls.update_library(session, library)
updates['updated_notes'] = cls.update_notes(session, library, updates['update_list'])
elif updated_timestamp:
cls.update_library(session, library)

return updates

def load_parameters(self, request):
Expand Down
Loading