From c8cccf450066b5aa9cac2c54b1c6be9893876e95 Mon Sep 17 00:00:00 2001 From: trivernis Date: Wed, 10 Nov 2021 21:33:48 +0100 Subject: [PATCH] Fix performance issues with rendering on import Signed-off-by: trivernis --- mediarepo-ui/src/app/models/AddFileOptions.ts | 2 +- .../filesystem-import.component.ts | 24 ++++++++++++------- .../import-tab-sidebar.component.html | 2 +- .../import-tab-sidebar.component.ts | 2 ++ .../home/import-tab/import-tab.component.html | 2 +- .../home/import-tab/import-tab.component.ts | 24 +++++++++++++++---- 6 files changed, 40 insertions(+), 16 deletions(-) diff --git a/mediarepo-ui/src/app/models/AddFileOptions.ts b/mediarepo-ui/src/app/models/AddFileOptions.ts index ef3c71c..120ac61 100644 --- a/mediarepo-ui/src/app/models/AddFileOptions.ts +++ b/mediarepo-ui/src/app/models/AddFileOptions.ts @@ -1,5 +1,5 @@ export class AddFileOptions { - public read_tags_from_txt = false; + public read_tags_from_txt = true; public delete_after_import = false; constructor() { diff --git a/mediarepo-ui/src/app/pages/home/import-tab/import-tab-sidebar/filesystem-import/filesystem-import.component.ts b/mediarepo-ui/src/app/pages/home/import-tab/import-tab-sidebar/filesystem-import/filesystem-import.component.ts index a470fdc..09459b2 100644 --- a/mediarepo-ui/src/app/pages/home/import-tab/import-tab-sidebar/filesystem-import/filesystem-import.component.ts +++ b/mediarepo-ui/src/app/pages/home/import-tab/import-tab-sidebar/filesystem-import/filesystem-import.component.ts @@ -13,6 +13,7 @@ import {File} from "../../../../../models/File"; export class FilesystemImportComponent { @Output() fileImported = new EventEmitter(); + @Output() importFinished = new EventEmitter(); public fileCount: number = 0; public files: FileOsMetadata[] = []; @@ -40,18 +41,23 @@ export class FilesystemImportComponent { public async import() { this.importing = true; - this.importingProgress = 0; - for (const file of this.files) { - try { - const resultFile = await this.importService.addLocalFile(file, this.importOptions); + this.importingProgress = 0; + let count = 0; + + for (const file of this.files) { + try { + const resultFile = await this.importService.addLocalFile(file, + this.importOptions); this.fileImported.emit(resultFile); - } catch (err) { - console.log(err); - this.errorBroker.showError(err); - } - this.importingProgress++; + } catch (err) { + console.log(err); + this.errorBroker.showError(err); } + count++; + this.importingProgress = (count / this.fileCount) * 100; + } this.importing = false; + this.importFinished.emit(); } } diff --git a/mediarepo-ui/src/app/pages/home/import-tab/import-tab-sidebar/import-tab-sidebar.component.html b/mediarepo-ui/src/app/pages/home/import-tab/import-tab-sidebar/import-tab-sidebar.component.html index 66497ec..84de2f8 100644 --- a/mediarepo-ui/src/app/pages/home/import-tab/import-tab-sidebar/import-tab-sidebar.component.html +++ b/mediarepo-ui/src/app/pages/home/import-tab/import-tab-sidebar/import-tab-sidebar.component.html @@ -12,7 +12,7 @@
- +
diff --git a/mediarepo-ui/src/app/pages/home/import-tab/import-tab-sidebar/import-tab-sidebar.component.ts b/mediarepo-ui/src/app/pages/home/import-tab/import-tab-sidebar/import-tab-sidebar.component.ts index 673d98f..546476c 100644 --- a/mediarepo-ui/src/app/pages/home/import-tab/import-tab-sidebar/import-tab-sidebar.component.ts +++ b/mediarepo-ui/src/app/pages/home/import-tab/import-tab-sidebar/import-tab-sidebar.component.ts @@ -16,5 +16,7 @@ import {File} from "../../../../models/File"; export class ImportTabSidebarComponent { @Output() fileImported = new EventEmitter(); + @Output() importFinished = new EventEmitter(); + constructor() { } } diff --git a/mediarepo-ui/src/app/pages/home/import-tab/import-tab.component.html b/mediarepo-ui/src/app/pages/home/import-tab/import-tab.component.html index f9daa0c..a512144 100644 --- a/mediarepo-ui/src/app/pages/home/import-tab/import-tab.component.html +++ b/mediarepo-ui/src/app/pages/home/import-tab/import-tab.component.html @@ -1,6 +1,6 @@ - + diff --git a/mediarepo-ui/src/app/pages/home/import-tab/import-tab.component.ts b/mediarepo-ui/src/app/pages/home/import-tab/import-tab.component.ts index db9d560..f26b3c0 100644 --- a/mediarepo-ui/src/app/pages/home/import-tab/import-tab.component.ts +++ b/mediarepo-ui/src/app/pages/home/import-tab/import-tab.component.ts @@ -1,5 +1,6 @@ -import { Component, OnInit } from '@angular/core'; +import {Component} from '@angular/core'; import {File} from "../../../models/File"; +import {FileService} from "../../../services/file/file.service"; @Component({ selector: 'app-import-tab', @@ -10,11 +11,26 @@ export class ImportTabComponent { public files: File[] = []; - constructor() { } + constructor(private fileService: FileService) { + } - public addFileFromImport(file: File) { + /** + * Adds an imported file to the list of imported files + * @param {File} file + * @returns {Promise} + */ + public async addFileFromImport(file: File) { this.files.push(file); - this.files = [...this.files]; + if (this.files.length % 50 === 0) { // refresh every 50 pictures + this.refreshFileView(); + } } + /** + * Refreshes the file view + * @returns {Promise} + */ + public refreshFileView() { + this.files = [...this.files]; + } }