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

holding: better delete_standard_holdings_having_no_items #2724

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
23 changes: 12 additions & 11 deletions rero_ils/modules/holdings/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@
@shared_task(ignore_result=True)
def delete_standard_holdings_having_no_items():
"""Removes standard holdings records with no attached items."""
current_app.logger.debug(
"Starting delete_standard_holdings_having_no_items task ...")
es_query = HoldingsSearch() \
.filter('term', holdings_type='standard') \
.filter('term', items_count=0) \
.source('pid')

deleted = 0
errors = 0
for hit in es_query.scan():
record = Holding.get_record_by_pid(hit.pid)
record.delete(force=False, dbcommit=True, delindex=True)
deleted += 1

current_app.logger.debug("Ending delete_standard_holdings_having_no_items")
msg = f'Number of removed holdings: {es_query.count()}'
set_timestamp('holdings-deletion', deleted=deleted)
return msg
try:
record.delete(force=False, dbcommit=True, delindex=True)
except Exception as err:
errors += 1
reasons = record.reasons_not_to_delete()
current_app.logger.error(
f'Can not delete standard holding: {hit.pid} {reasons} {err}')

counts = {'count': es_query.count(), 'errors': errors}
set_timestamp('delete_standard_holdings_having_no_items', **counts)
return counts