diff options
| author | Acid Chicken (硫酸鶏) <root@acid-chicken.com> | 2023-07-20 17:00:54 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-20 17:00:54 +0900 |
| commit | e6fca721715c0ee070aba922c2815c3d44825765 (patch) | |
| tree | 78daa2e140b4c16435d771d0d2d4a47a7e3a24c3 /packages/backend/src/queue | |
| parent | 13.14.0-beta.7 (diff) | |
| download | sharkey-e6fca721715c0ee070aba922c2815c3d44825765.tar.gz sharkey-e6fca721715c0ee070aba922c2815c3d44825765.tar.bz2 sharkey-e6fca721715c0ee070aba922c2815c3d44825765.zip | |
perf: use slacc instead of unzipper (#10780)
Co-authored-by: tamaina <tamaina@hotmail.co.jp>
Diffstat (limited to 'packages/backend/src/queue')
| -rw-r--r-- | packages/backend/src/queue/processors/ImportCustomEmojisProcessorService.ts | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/packages/backend/src/queue/processors/ImportCustomEmojisProcessorService.ts b/packages/backend/src/queue/processors/ImportCustomEmojisProcessorService.ts index 4ba749ec52..37b929cb03 100644 --- a/packages/backend/src/queue/processors/ImportCustomEmojisProcessorService.ts +++ b/packages/backend/src/queue/processors/ImportCustomEmojisProcessorService.ts @@ -1,7 +1,7 @@ import * as fs from 'node:fs'; import { Inject, Injectable } from '@nestjs/common'; +import { ZipReader } from 'slacc'; import { DataSource } from 'typeorm'; -import unzipper from 'unzipper'; import { DI } from '@/di-symbols.js'; import type { EmojisRepository, DriveFilesRepository, UsersRepository } from '@/models/index.js'; import type { Config } from '@/config.js'; @@ -72,9 +72,9 @@ export class ImportCustomEmojisProcessorService { } const outputPath = path + '/emojis'; - const unzipStream = fs.createReadStream(destPath); - const extractor = unzipper.Extract({ path: outputPath }); - extractor.on('close', async () => { + try { + this.logger.succ(`Unzipping to ${outputPath}`); + ZipReader.withDestinationPath(outputPath).viaBuffer(await fs.promises.readFile(destPath)); const metaRaw = fs.readFileSync(outputPath + '/meta.json', 'utf-8'); const meta = JSON.parse(metaRaw); @@ -115,8 +115,12 @@ export class ImportCustomEmojisProcessorService { cleanup(); this.logger.succ('Imported'); - }); - unzipStream.pipe(extractor); - this.logger.succ(`Unzipping to ${outputPath}`); + } catch (e) { + if (e instanceof Error || typeof e === 'string') { + this.logger.error(e); + } + cleanup(); + throw e; + } } } |