earlSt1 / vtt-compendium-folders

Collapsable folders in the compendium directory and folder structures inside compendiums for FoundryVTT
21 stars 18 forks source link

V11 migration - ensure macro never called twice quickly #208

Open farling42 opened 1 year ago

farling42 commented 1 year ago

Thanks for all the hard work you've done in the past for CF.

For the migration, is it possible to provide a lock so that the migration function can't be called again before a previous call has finished?

Since CF has always cached the currently open folder, this can cause problems if trying to migrate two compendiums at the same time (since the most recently started compendium will be in the cache, and cause the other compendium to be wrongly set up).

earlSt1 commented 1 year ago

Hi, sure I can add a flag that is set when the module runs a migration. I initially intended for you to only be able to run one migration at a time, but i can see how running multiple migrations would break things

farling42 commented 1 year ago

I have a lot of compendiums in shared modules, so I'm using the following script, but others might not be so careful:

for (const pack of game.packs.values()) {
     const packid = pack.metadata.id
     const locked = pack.locked;
     console.log(`Migrating ${packid}`)
     if (locked) pack.configure({locked:false});
     await game.CF.FICFolderAPI.migrateCompendium(packid);
     if (locked) pack.configure({locked:true});
     console.log(`Finished ${packid}`);
}
console.log('** FINISHED CF MIGRATION **')

My first attempt at a script was using forEach, but that didn't seem to serialize the calls to migrateCompendium properly.