Skip to content

Conversation

@fw-bot
Copy link
Contributor

@fw-bot fw-bot commented Feb 19, 2025

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.

Forward-Port-Of: #198202
Forward-Port-Of: #198124

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.

X-original-commit: 7d14677
@robodoo
Copy link
Contributor

robodoo commented Feb 19, 2025

Pull request status dashboard

@fw-bot
Copy link
Contributor Author

fw-bot commented Feb 19, 2025

This PR targets saas-17.4 and is part of the forward-port chain. Further PRs will be created up to master.

More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port

@robodoo robodoo added the forwardport This PR was created by @fw-bot label Feb 19, 2025
@C3POdoo C3POdoo added the RD research & development, internal work label Feb 19, 2025
robodoo pushed a commit that referenced this pull request Feb 20, 2025
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 #198443

X-original-commit: 7d14677
Signed-off-by: Raphael Collet <rco@odoo.com>
@robodoo robodoo closed this Feb 20, 2025
@fw-bot fw-bot deleted the saas-17.4-16.0-prefetch-new-lines-rco-416993-fw branch March 6, 2025 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

forwardport This PR was created by @fw-bot RD research & development, internal work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants