Skip to content

Commit

Permalink
parallelised everything except line 233 of Directory.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
edsilv committed Oct 5, 2018
1 parent 7121f71 commit db538d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
10 changes: 5 additions & 5 deletions Canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class Canvas {

let hasPaintingAnnotation: boolean = false;

for (const file of customAnnotationFiles) {
await Promise.all(customAnnotationFiles.map(async (file: string) => {

let directoryName: string = dirname(file);
directoryName = directoryName.substr(directoryName.lastIndexOf('/'));
Expand Down Expand Up @@ -181,7 +181,7 @@ export class Canvas {
}

canvasJson.items[0].items.push(annotationJson);
}
}));

if (!hasPaintingAnnotation) {
// for each jpg/pdf/mp4/obj in the canvas directory
Expand Down Expand Up @@ -216,8 +216,8 @@ export class Canvas {

private async _annotateFiles(canvasJson: any, files: string[]): Promise<void> {

for (let file of files) {
await Promise.all(files.map(async (file: string) => {

file = Utils.normaliseFilePath(file);
const extName: string = extname(file);

Expand Down Expand Up @@ -258,7 +258,7 @@ export class Canvas {
annotationJson.body.height = height;
}
}
}
}));
}

private async _getInfo(): Promise<void> {
Expand Down
18 changes: 6 additions & 12 deletions Directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,10 @@ export class Directory {
return Utils.compare(a, b);
});

// example of parallel processing
//await Promise.all(canvases.map(async (canvas: string) => { ... });

// dropped parallel processing in favour of "deterministic" results
// also, a lot of tasks in parallel can use too much memory:
// https://blog.lavrton.com/javascript-loops-how-to-handle-async-await-6252dd3c795
for (const canvas of canvases) {
await Promise.all(canvases.map(async (canvas: string) => {
console.log(chalk.green('creating canvas for: ') + canvas);
this.items.push(new Canvas(canvas, this));
}
}));

// directories not starting with an underscore
// these can be child manifests or child collections
Expand All @@ -80,14 +74,14 @@ export class Directory {
return Utils.compare(a, b);
});

for (const directory of directories) {
await Promise.all(directories.map(async (directory: string) => {
console.log(chalk.green('creating directory for: ') + directory);
const name: string = basename(directory);
const url: string = urljoin(this.url.href, name);
const newDirectory: Directory = new Directory(directory, url, this.generateThumbs, undefined, this);
await newDirectory.read();
this.directories.push(newDirectory);
}
}));

// if there are no canvas, manifest, or collection directories to read,
// but there are paintable files in the current directory,
Expand Down Expand Up @@ -164,7 +158,7 @@ export class Directory {

// for each child directory, add a collectionitem or manifestitem json boilerplate to items.

for (const directory of this.directories) {
await Promise.all(this.directories.map(async (directory: Directory) => {
let itemJson: any;

if (directory.isCollection) {
Expand All @@ -179,7 +173,7 @@ export class Directory {
await Utils.getThumbnail(itemJson, directory);

this.indexJson.items.push(itemJson);
}
}));

// check for manifests.yml. if it exists, parse and add to items
const hasManifestsYml: boolean = await Utils.hasManifestsYml(this.directoryPath);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "biiif",
"version": "0.3.14",
"version": "0.3.15",
"description": "A CLI to build IIIF collections",
"main": "index.js",
"repository": {
Expand Down

0 comments on commit db538d6

Please sign in to comment.