Skip to content

[IMP] edi_core_oca: optimize exchange file lookups - #374

Open
simahawk wants to merge 3 commits into
OCA:18.0from
camptocamp:18-edi-oca-exchange-file-search
Open

simahawk wants to merge 3 commits into
OCA:18.0from
camptocamp:18-edi-oca-exchange-file-search

Conversation

@simahawk

Copy link
Copy Markdown
Contributor

port of #349 + 2 additional fixes.

Searching on exchange_file (Binary, attachment=True) generates subqueries
on ir_attachment, which is costly in batch cron flows.

Add a stored has_exchange_file boolean on edi.exchange.record, kept in
sync through the exchange_file inverse, and use it in the output and
input pending domains. Existing records are backfilled by the migration.

Port of OCA#349 (16.0) to 18.0.
_output_check_send only needs to know whether a file exists, but reading
exchange_file loads its full content. When the attachment lives in a
filesystem storage, this triggers a storage lookup and a connection check
on every send. Read the attachment size instead (bin_size context), which
gives the same answer without touching the content.
…hecks

exchange_file_frozen is computed on every record read and the file manager
checks file presence on each form load. Both only need to know whether a
file exists, so read the attachment size (bin_size context) instead of
loading the content from the storage.
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @etobella,
some modules you are maintaining are being modified, check this out!

@OCA-git-bot OCA-git-bot added series:18.0 mod:edi_core_oca Module edi_core_oca mod:edi_exchange_record_file_manager Module edi_exchange_record_file_manager labels Oct 20, 2026
for rec in self:
rec.exchange_file_frozen = bool(
rec.exchange_file
rec.with_context(bin_size=True).exchange_file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we have the boolen why we use this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume it's a performance improvement. Using bin_size=True will prevent Odoo from loading the whole file from the filestore or the DB, encoding it via base64 and storing the whole file content in the cache (just to check whether it exists); instead it will simply read the stored field file_size and return None if there's no file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but the boolean is stored and it should be faster to search on the database than checking the size of a file, isn't it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's right. I thought you were talking about the bool() used in the snippet, not the Boolean field itself, my bad 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:edi_core_oca Module edi_core_oca mod:edi_exchange_record_file_manager Module edi_exchange_record_file_manager series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants