Repository navigation
Conversation
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.
|
Hi @etobella, |
| for rec in self: | ||
| rec.exchange_file_frozen = bool( | ||
| rec.exchange_file | ||
| rec.with_context(bin_size=True).exchange_file |
There was a problem hiding this comment.
if we have the boolen why we use this?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Yeah, that's right. I thought you were talking about the bool() used in the snippet, not the Boolean field itself, my bad 😅
port of #349 + 2 additional fixes.