timeline: refactor RAW stacking logic

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/953/head
Varun Patil 2023-11-22 12:39:08 -08:00
parent fec834855e
commit e55f0d6343
1 changed files with 28 additions and 35 deletions

View File

@ -1054,8 +1054,7 @@ export default defineComponent({
// Set of basenames without extension
const res1: IPhoto[] = [];
const files = new Map<string, IPhoto[]>();
let need2 = false;
const toStack = new Map<string, IPhoto[]>();
// First pass -- remove hidden and prepare
for (const photo of data) {
@ -1069,50 +1068,44 @@ export default defineComponent({
const basename = utils.removeExtension(photo.basename ?? String());
if (!basename) continue; // huh?
// Skip for raw files
// Store RAW files for stacking
if (this.config.stack_raw_files && photo.mimetype === this.c.MIME_RAW) {
need2 = true;
continue;
const files = toStack.get(basename);
if (!files) {
toStack.set(basename, [photo]);
} else {
files.push(photo);
}
// Store file basenames without extension
let fileList = files.get(basename);
if (!fileList) {
fileList = [];
files.set(basename, fileList);
}
fileList.push(photo);
}
// Skip second pass unless needed
if (!need2) return res1;
if (!toStack.size) return res1;
// File IDs that have been stacked
const stacked = new Set<IPhoto>();
// Second pass -- stack files
const res2: IPhoto[] = [];
for (const photo of res1) {
// Remove RAW files if they can be stacked
if (this.config.stack_raw_files && photo.mimetype === this.c.MIME_RAW) {
// Get first matching non-raw file
if (photo.mimetype === this.c.MIME_RAW) {
continue; // never stack over RAW
}
// Check if any RAW files can be stacked
const basename = utils.removeExtension(photo.basename ?? String());
const files = toStack.get(basename) ?? [];
// Get the list of files with the same basename
const fileList = files.get(basename);
if (fileList?.length) {
// Move top file to end (min priority)
const top = fileList.shift()!;
fileList.push(top);
if (!files.length) continue;
// Stack on top file
top.stackraw ??= [];
top.stackraw.push(photo);
// Stack on top of this file
photo.stackraw = files;
// Do not add this to result
continue;
}
// Mark as stacked
files.forEach((f) => stacked.add(f));
}
res2.push(photo);
}
// Remove files that were stacked
const res2 = res1.filter((p) => !stacked.has(p));
return res2;
},