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

Optimize deleting large calendars #50

Open
thomasst opened this issue Aug 30, 2021 · 0 comments
Open

Optimize deleting large calendars #50

thomasst opened this issue Aug 30, 2021 · 0 comments

Comments

@thomasst
Copy link
Member

def _delete_calendar(db_session, calendar):
"""
Delete the calendar after deleting its events in batches.
Note we deliberately do not rely on the configured delete cascade -- doing
so for a calendar with many events can result in the session post-flush
processing (Transaction record creation) blocking the event loop.
"""
count = 0
for e in calendar.events:
db_session.delete(e)
count += 1
if count % 100 == 0:
# Issue a DELETE for every 100 events.
# This will ensure that when the DELETE for the calendar is issued,
# the number of objects in the session and for which to create
# Transaction records is small.
db_session.commit()
db_session.commit()
# Delete the calendar
db_session.delete(calendar)
db_session.commit()
is fetching all the calendar data, which is inefficient and causes timeouts.

We should use DELETE with a LIMIT until there are no events (~1s for a batch size of 1K, ~4s for a batch size of 10K).

DELETE FROM event WHERE calendar_id=XXXX LIMIT 1000;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant