-
Notifications
You must be signed in to change notification settings - Fork 70
[FIX] recompute_fields: get ids in batches #303
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
Conversation
upgradeci retry with always only account |
This has the disadvantage of splitting the I would keep one loop if ids is None:
cr.execute("SELECT COUNT(id) FROM ...")
[count] = cr.fetchone()
else:
count = len(ids)
if strategy == "auto":
big_table = count > BIG_TABLE_THRESHOLD
...
size = (count + chunk_size - 1) / chunk_size
def get_ids():
if ids is not None:
for id_ in ids:
yield id_
MAX_SIZE = 1000000
with named_cursor(cr, MAX_SIZE) as ncr:
ncr.execute("SELECT id FROM ...")
for (id_,) in ncr:
yield id_
for subids in log_progress(chunks(get_ids(), chunk_size, list), logger, qualifier=qual, size=size):
... |
86b8e00
to
a82fb9d
Compare
all comments applied |
If no ids are given to recompute, the util will fetch all ids in the target table and then recompute in chunks. Fetching all the ids itself can cause a memory error if the table is too large. Using a named cursor with a limit of 1M records to fetch can eliminate this possibility.
a82fb9d
to
321eba9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@robodoo r+ priority
If no ids are given to recompute, the util will fetch all ids in the target table and then recompute in chunks. Fetching all the ids itself can cause a memory error if the table is too large.
Using a named cursor with a limit of 1M records to fetch can eliminate this possibility.
opw-4909458
upg-3106002