@@ -122,6 +122,47 @@ public static List<DatasetThumbnail> getThumbnailCandidates(Dataset dataset, boo
122122 return thumbnails ;
123123 }
124124
125+ /**
126+ * Returns thumbnail candidates as lazy DatasetThumbnail objects that hold
127+ * only DataFile references. Base64 images are generated on-demand when
128+ * getBase64image() is called, deferring expensive storage I/O until the
129+ * thumbnail is actually displayed.
130+ *
131+ * @param dataset the dataset to find thumbnail candidates for
132+ * @return list of lazy DatasetThumbnail objects (base64 not pre-computed)
133+ */
134+ public static List <DatasetThumbnail > getLazyThumbnailCandidates (Dataset dataset ) {
135+ List <DatasetThumbnail > thumbnails = new ArrayList <>();
136+ if (dataset == null ) {
137+ return thumbnails ;
138+ }
139+ // Use database-level filtering to get only thumbnail-candidate files (images, PDFs)
140+ // instead of iterating through all files in the dataset.
141+ // Fall back to iterating all files if CDI is not available (e.g., unit tests).
142+ List <FileMetadata > candidateFileMetadatas ;
143+ try {
144+ DataFileServiceBean dataFileService = CDI .current ().select (DataFileServiceBean .class ).get ();
145+ candidateFileMetadatas = dataFileService .findThumbnailCandidateFileMetadatasByDatasetVersionId (dataset .getLatestVersion ().getId ());
146+ } catch (IllegalStateException ex ) {
147+ // CDI not available (e.g., unit tests) - fall back to iterating all files
148+ candidateFileMetadatas = dataset .getLatestVersion ().getFileMetadatas ();
149+ }
150+ for (FileMetadata fileMetadata : candidateFileMetadatas ) {
151+ DataFile dataFile = fileMetadata .getDataFile ();
152+
153+ if (dataFile != null && FileUtil .isThumbnailSupported (dataFile )
154+ && !dataFile .isRestricted ()
155+ && !FileUtil .isActivelyEmbargoed (dataFile )
156+ && ImageThumbConverter .isThumbnailAvailable (dataFile )
157+ ) {
158+ // Create lazy thumbnail — base64 will be generated on first access
159+ DatasetThumbnail datasetThumbnail = new DatasetThumbnail (dataFile );
160+ thumbnails .add (datasetThumbnail );
161+ }
162+ }
163+ return thumbnails ;
164+ }
165+
125166 /**
126167 * Note "datasetVersionId" can be null. If needed, it helps the "efficiency"
127168 * of "attemptToAutomaticallySelectThumbnailFromDataFiles"
0 commit comments