perf(ui): download only images and optimize image selection for document edit view, prioritize best-fit size (#11844)
### What? In the same vein as #11696, this PR optimizes how images are selected for display in the document edit view. It ensures that only image files are processed and selects the most appropriate size to minimize unnecessary downloads and improve performance. #### Previously: - Non-image files were being processed unnecessarily, despite not generating thumbnails. - Images without a `thumbnailURL` defaulted to their original full size, even when smaller, optimized versions were available. #### Now: - **Only images** are processed for thumbnails, avoiding redundant requests for non-images. - **The smallest available image within a target range** (`40px - 180px`) is prioritized for display. - **If no images fit within this range**, the logic selects: - The next smallest larger image (if available). - The **original** image if it is smaller than the next available larger size. - The largest **smaller** image if no better fit exists. ### Why? Prevents unnecessary downloads of non-image files, reduces bandwidth usage by selecting more efficient image sizes and improves load times and performance in the edit view. ### How? - **Filters out non-image files** when determining which assets to display. - Uses the same algorithm as in #11696 but turns it into a reusable function to be used in various areas around the codebase. Namely the upload field hasOne and hasMany components. Before (4.5mb transfer):  After (15.9kb transfer): 
This commit is contained in:
@@ -101,6 +101,7 @@ export interface Config {
|
||||
'media-without-relation-preview': MediaWithoutRelationPreview;
|
||||
'relation-preview': RelationPreview;
|
||||
'hide-file-input-on-create': HideFileInputOnCreate;
|
||||
'best-fit': BestFit;
|
||||
users: User;
|
||||
'payload-locked-documents': PayloadLockedDocument;
|
||||
'payload-preferences': PayloadPreference;
|
||||
@@ -142,6 +143,7 @@ export interface Config {
|
||||
'media-without-relation-preview': MediaWithoutRelationPreviewSelect<false> | MediaWithoutRelationPreviewSelect<true>;
|
||||
'relation-preview': RelationPreviewSelect<false> | RelationPreviewSelect<true>;
|
||||
'hide-file-input-on-create': HideFileInputOnCreateSelect<false> | HideFileInputOnCreateSelect<true>;
|
||||
'best-fit': BestFitSelect<false> | BestFitSelect<true>;
|
||||
users: UsersSelect<false> | UsersSelect<true>;
|
||||
'payload-locked-documents': PayloadLockedDocumentsSelect<false> | PayloadLockedDocumentsSelect<true>;
|
||||
'payload-preferences': PayloadPreferencesSelect<false> | PayloadPreferencesSelect<true>;
|
||||
@@ -1260,6 +1262,19 @@ export interface RelationPreview {
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "best-fit".
|
||||
*/
|
||||
export interface BestFit {
|
||||
id: string;
|
||||
withAdminThumbnail?: (string | null) | AdminThumbnailFunction;
|
||||
withinRange?: (string | null) | Enlarge;
|
||||
nextSmallestOutOfRange?: (string | null) | FocalOnly;
|
||||
original?: (string | null) | FocalOnly;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "users".
|
||||
@@ -1420,6 +1435,10 @@ export interface PayloadLockedDocument {
|
||||
relationTo: 'hide-file-input-on-create';
|
||||
value: string | HideFileInputOnCreate;
|
||||
} | null)
|
||||
| ({
|
||||
relationTo: 'best-fit';
|
||||
value: string | BestFit;
|
||||
} | null)
|
||||
| ({
|
||||
relationTo: 'users';
|
||||
value: string | User;
|
||||
@@ -2632,6 +2651,18 @@ export interface HideFileInputOnCreateSelect<T extends boolean = true> {
|
||||
focalX?: T;
|
||||
focalY?: T;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "best-fit_select".
|
||||
*/
|
||||
export interface BestFitSelect<T extends boolean = true> {
|
||||
withAdminThumbnail?: T;
|
||||
withinRange?: T;
|
||||
nextSmallestOutOfRange?: T;
|
||||
original?: T;
|
||||
updatedAt?: T;
|
||||
createdAt?: T;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "users_select".
|
||||
|
||||
Reference in New Issue
Block a user