-
Couldn't load subscription status.
- Fork 30.2k
[FIX] core: prefetching of secondary new records #198124
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
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, I have just two small comments/questions.
odoo/fields.py
Outdated
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.
| for rec in recs: | |
| if rec._origin: | |
| value = self.convert_to_cache(rec._origin[self.name], rec, validate=False) | |
| env.cache.set(rec, self, value) | |
| for rec in recs: | |
| if (origin_rec := rec._origin): | |
| value = self.convert_to_cache(origin_rec[self.name], rec, validate=False) | |
| env.cache.set(rec, self, value) |
Maybe to avoid recreating rec._origin twice?
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.
Odoo 16 requires Python 3.7 minimum, and the walrus operator has been introduced in Python 3.8.
I will adapt this in forward-ports.
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.
Tested on my original issue in 18.0 and it works as expected 👍
Consider a recordset of new records, and a loop like
for record in records:
for line in record.line_ids:
line.value
The implementation of `record.line_ids` does not actually prefetch all
`records`. It actually fetches the field on the records' origin (their
corresponding real records), but only assigns the current new record in
cache. As the prefetching relies on the cached values of `line_ids`,
the prefetching mechanism is actually broken on `line`.
The fix consists in assigning all the records to prefetch in this case.
This does not add unexpected prefetching, since the origin records are
prefetched as one batch anyway.
3e31c0b to
d2fac4f
Compare
|
@robodoo r+ |
Consider a recordset of new records, and a loop like
for record in records:
for line in record.line_ids:
line.value
The implementation of `record.line_ids` does not actually prefetch all
`records`. It actually fetches the field on the records' origin (their
corresponding real records), but only assigns the current new record in
cache. As the prefetching relies on the cached values of `line_ids`,
the prefetching mechanism is actually broken on `line`.
The fix consists in assigning all the records to prefetch in this case.
This does not add unexpected prefetching, since the origin records are
prefetched as one batch anyway.
closes #198124
Signed-off-by: Raphael Collet <rco@odoo.com>
Consider a recordset of new records, and a loop like
for record in records:
for line in record.line_ids:
line.value
The implementation of `record.line_ids` does not actually prefetch all
`records`. It actually fetches the field on the records' origin (their
corresponding real records), but only assigns the current new record in
cache. As the prefetching relies on the cached values of `line_ids`,
the prefetching mechanism is actually broken on `line`.
The fix consists in assigning all the records to prefetch in this case.
This does not add unexpected prefetching, since the origin records are
prefetched as one batch anyway.
closes odoo#198124
Signed-off-by: Raphael Collet <rco@odoo.com>
Consider a recordset of new records, and a loop like
for record in records:
for line in record.line_ids:
line.value
The implementation of `record.line_ids` does not actually prefetch all
`records`. It actually fetches the field on the records' origin (their
corresponding real records), but only assigns the current new record in
cache. As the prefetching relies on the cached values of `line_ids`,
the prefetching mechanism is actually broken on `line`.
The fix consists in assigning all the records to prefetch in this case.
This does not add unexpected prefetching, since the origin records are
prefetched as one batch anyway.
closes odoo#198124
Signed-off-by: Raphael Collet <rco@odoo.com>
Consider a recordset of new records, and a loop like
for record in records:
for line in record.line_ids:
line.value
The implementation of `record.line_ids` does not actually prefetch all
`records`. It actually fetches the field on the records' origin (their
corresponding real records), but only assigns the current new record in
cache. As the prefetching relies on the cached values of `line_ids`,
the prefetching mechanism is actually broken on `line`.
The fix consists in assigning all the records to prefetch in this case.
This does not add unexpected prefetching, since the origin records are
prefetched as one batch anyway.
closes odoo#198124
Signed-off-by: Raphael Collet <rco@odoo.com>
Consider a recordset of new records, and a loop like
for record in records:
for line in record.line_ids:
line.value
The implementation of `record.line_ids` does not actually prefetch all
`records`. It actually fetches the field on the records' origin (their
corresponding real records), but only assigns the current new record in
cache. As the prefetching relies on the cached values of `line_ids`,
the prefetching mechanism is actually broken on `line`.
The fix consists in assigning all the records to prefetch in this case.
This does not add unexpected prefetching, since the origin records are
prefetched as one batch anyway.
closes odoo#198124
Signed-off-by: Raphael Collet <rco@odoo.com>
Consider a recordset of new records, and a loop like
for record in records:
for line in record.line_ids:
line.value
The implementation of `record.line_ids` does not actually prefetch all
`records`. It actually fetches the field on the records' origin (their
corresponding real records), but only assigns the current new record in
cache. As the prefetching relies on the cached values of `line_ids`,
the prefetching mechanism is actually broken on `line`.
The fix consists in assigning all the records to prefetch in this case.
This does not add unexpected prefetching, since the origin records are
prefetched as one batch anyway.
closes odoo#198124
Signed-off-by: Raphael Collet <rco@odoo.com>
Consider a recordset of new records, and a loop like
for record in records:
for line in record.line_ids:
line.value
The implementation of `record.line_ids` does not actually prefetch all
`records`. It actually fetches the field on the records' origin (their
corresponding real records), but only assigns the current new record in
cache. As the prefetching relies on the cached values of `line_ids`,
the prefetching mechanism is actually broken on `line`.
The fix consists in assigning all the records to prefetch in this case.
This does not add unexpected prefetching, since the origin records are
prefetched as one batch anyway.
closes odoo#198124
Signed-off-by: Raphael Collet <rco@odoo.com>
Consider a recordset of new records, and a loop like
for record in records:
for line in record.line_ids:
line.value
The implementation of `record.line_ids` does not actually prefetch all
`records`. It actually fetches the field on the records' origin (their
corresponding real records), but only assigns the current new record in
cache. As the prefetching relies on the cached values of `line_ids`,
the prefetching mechanism is actually broken on `line`.
The fix consists in assigning all the records to prefetch in this case.
This does not add unexpected prefetching, since the origin records are
prefetched as one batch anyway.
closes odoo#198124
Signed-off-by: Raphael Collet <rco@odoo.com>
Consider a recordset of new records, and a loop like
for record in records:
for line in record.line_ids:
line.value
The implementation of `record.line_ids` does not actually prefetch all
`records`. It actually fetches the field on the records' origin (their
corresponding real records), but only assigns the current new record in
cache. As the prefetching relies on the cached values of `line_ids`,
the prefetching mechanism is actually broken on `line`.
The fix consists in assigning all the records to prefetch in this case.
This does not add unexpected prefetching, since the origin records are
prefetched as one batch anyway.
closes odoo#198124
Signed-off-by: Raphael Collet <rco@odoo.com>
Consider a recordset of new records, and a loop like
for record in records:
for line in record.line_ids:
line.value
The implementation of `record.line_ids` does not actually prefetch all
`records`. It actually fetches the field on the records' origin (their
corresponding real records), but only assigns the current new record in
cache. As the prefetching relies on the cached values of `line_ids`,
the prefetching mechanism is actually broken on `line`.
The fix consists in assigning all the records to prefetch in this case.
This does not add unexpected prefetching, since the origin records are
prefetched as one batch anyway.
closes odoo#198124
Signed-off-by: Raphael Collet <rco@odoo.com>
Consider a recordset of new records, and a loop like
for record in records:
for line in record.line_ids:
line.value
The implementation of `record.line_ids` does not actually prefetch all
`records`. It actually fetches the field on the records' origin (their
corresponding real records), but only assigns the current new record in
cache. As the prefetching relies on the cached values of `line_ids`,
the prefetching mechanism is actually broken on `line`.
The fix consists in assigning all the records to prefetch in this case.
This does not add unexpected prefetching, since the origin records are
prefetched as one batch anyway.
closes odoo#198124
Signed-off-by: Raphael Collet <rco@odoo.com>
Consider a recordset of new records, and a loop like
for record in records:
for line in record.line_ids:
line.value
The implementation of `record.line_ids` does not actually prefetch all
`records`. It actually fetches the field on the records' origin (their
corresponding real records), but only assigns the current new record in
cache. As the prefetching relies on the cached values of `line_ids`,
the prefetching mechanism is actually broken on `line`.
The fix consists in assigning all the records to prefetch in this case.
This does not add unexpected prefetching, since the origin records are
prefetched as one batch anyway.
closes odoo#198124
Signed-off-by: Raphael Collet <rco@odoo.com>
Consider a recordset of new records, and a loop like
for record in records:
for line in record.line_ids:
line.value
The implementation of `record.line_ids` does not actually prefetch all
`records`. It actually fetches the field on the records' origin (their
corresponding real records), but only assigns the current new record in
cache. As the prefetching relies on the cached values of `line_ids`,
the prefetching mechanism is actually broken on `line`.
The fix consists in assigning all the records to prefetch in this case.
This does not add unexpected prefetching, since the origin records are
prefetched as one batch anyway.
closes odoo#198124
Signed-off-by: Raphael Collet <rco@odoo.com>

Consider a recordset of new records, and a loop like
The implementation of
record.line_idsdoes not actually prefetch allrecords. It actually fetches the field on the records' origin (their corresponding real records), but only assigns the current new record in cache. As the prefetching relies on the cached values ofline_ids, the prefetching mechanism is actually broken online.The fix consists in assigning all the records to prefetch in this case. This does not add unexpected prefetching, since the origin records are prefetched as one batch anyway.