[FIX] web_editor: avoid fetching optimized images which can't be shown

Before this commit, when opening the media dialog, the optimized images
would be fetched too.
An optimized image is an image related to an original one which received
some modification (crop etc).
Those optimized images are hidden by default, and can only be shown when
toggling the "Show optimized" option, which can be shown only in debug
mode.

So, fetching those images outside debug mode is:
1. Useless, as we don't do anything with those and never show them
2. Buggy sometimes, as a full patch of "Load more" images could be
   composed of only optimized images, meaning the "load more" will
   actually look like it did nothing, as all received images are (and
   will remain) hidden.

There is a tiny exception: if the edited image is an optimized one, we
still need to fetch it's attachment so we can show this image in the
media dialog as selected.

This fix thus filter out all the optimized images (except the one from
the explained exception) from the `search_read()`.

opw-3372811

closes odoo/odoo#127853

X-original-commit: 24177b5e2b56a94a51ac4b922d555beda9347611
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
Romain Derie
2023-07-10 16:59:18 +02:00
parent 3cc9836400
commit a1aa2db7c5
@@ -105,6 +105,31 @@ export class ImageSelector extends FileSelector {
}
domain.push('!', ['name', '=like', '%.crop']);
domain.push('|', ['type', '=', 'binary'], '!', ['url', '=like', '/%/static/%']);
// Optimized images (meaning they are related to an `original_id`) can
// only be shown in debug mode as the toggler to make those images
// appear is hidden when not in debug mode.
// There is thus no point to fetch those optimized images outside debug
// mode. Worst, it leads to bugs: it might fetch only optimized images
// when clicking on "load more" which will look like it's bugged as no
// images will appear on screen (they all will be hidden).
if (!this.env.debug) {
const subDomain = [false];
// Particular exception: if the edited image is an optimized
// image, we need to fetch it too so it's displayed as the
// selected image when opening the media dialog.
// We might get a few more optimized image than necessary if the
// original image has multiple optimized images but it's not a
// big deal.
const originalId = this.props.media && this.props.media.dataset.originalId;
if (originalId) {
subDomain.push(originalId);
}
domain.push(['original_id', 'in', subDomain]);
}
return domain;
}