Commit 9c117d90 authored by nanahira's avatar nanahira

format and remove

parent 741d633a
Pipeline #39036 failed with stages
in 4 minutes and 55 seconds
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
"@nestjs/serve-static": "^2.2.2", "@nestjs/serve-static": "^2.2.2",
"@nestjs/swagger": "^5.0.9", "@nestjs/swagger": "^5.0.9",
"@nestjs/typeorm": "^8.0.2", "@nestjs/typeorm": "^8.0.2",
"@sesamecare-oss/redlock": "^1.4.0",
"axios": "^0.21.1", "axios": "^0.21.1",
"better-lock": "^3.2.0", "better-lock": "^3.2.0",
"busboy": "^0.2.14", "busboy": "^0.2.14",
...@@ -3134,18 +3133,6 @@ ...@@ -3134,18 +3133,6 @@
"url": "https://github.com/chalk/chalk?sponsor=1" "url": "https://github.com/chalk/chalk?sponsor=1"
} }
}, },
"node_modules/@sesamecare-oss/redlock": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/@sesamecare-oss/redlock/-/redlock-1.4.0.tgz",
"integrity": "sha512-2z589R+yxKLN4CgKxP1oN4dsg6Y548SE4bVYam/R0kHk7Q9VrQ9l66q+k1ehhSLLY4or9hcchuF9/MhuuZdjJg==",
"license": "UNLICENSED",
"engines": {
"node": ">=16"
},
"peerDependencies": {
"ioredis": ">=5"
}
},
"node_modules/@sinonjs/commons": { "node_modules/@sinonjs/commons": {
"version": "1.8.3", "version": "1.8.3",
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.3.tgz", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.3.tgz",
...@@ -14299,12 +14286,6 @@ ...@@ -14299,12 +14286,6 @@
} }
} }
}, },
"@sesamecare-oss/redlock": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/@sesamecare-oss/redlock/-/redlock-1.4.0.tgz",
"integrity": "sha512-2z589R+yxKLN4CgKxP1oN4dsg6Y548SE4bVYam/R0kHk7Q9VrQ9l66q+k1ehhSLLY4or9hcchuF9/MhuuZdjJg==",
"requires": {}
},
"@sinonjs/commons": { "@sinonjs/commons": {
"version": "1.8.3", "version": "1.8.3",
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.3.tgz", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.3.tgz",
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
"@nestjs/serve-static": "^2.2.2", "@nestjs/serve-static": "^2.2.2",
"@nestjs/swagger": "^5.0.9", "@nestjs/swagger": "^5.0.9",
"@nestjs/typeorm": "^8.0.2", "@nestjs/typeorm": "^8.0.2",
"@sesamecare-oss/redlock": "^1.4.0",
"axios": "^0.21.1", "axios": "^0.21.1",
"better-lock": "^3.2.0", "better-lock": "^3.2.0",
"busboy": "^0.2.14", "busboy": "^0.2.14",
......
...@@ -28,7 +28,7 @@ import { RedisModule } from '@nestjs-modules/ioredis'; ...@@ -28,7 +28,7 @@ import { RedisModule } from '@nestjs-modules/ioredis';
rootPath: path.join(__dirname, '..', 'public'), rootPath: path.join(__dirname, '..', 'public'),
}), }),
ConfigModule.forRoot({ ConfigModule.forRoot({
isGlobal: true isGlobal: true,
}), }),
HttpModule, HttpModule,
TypeOrmModule.forRootAsync({ TypeOrmModule.forRootAsync({
...@@ -60,6 +60,6 @@ import { RedisModule } from '@nestjs-modules/ioredis'; ...@@ -60,6 +60,6 @@ import { RedisModule } from '@nestjs-modules/ioredis';
}), }),
], ],
controllers: [AppController, AdminController, UpdateController], controllers: [AppController, AdminController, UpdateController],
providers: [AppService, PackagerService, AssetsS3Service, PackageS3Service, UpdateService, MirrorService, /*LockService*/], providers: [AppService, PackagerService, AssetsS3Service, PackageS3Service, UpdateService, MirrorService /*LockService*/],
}) })
export class AppModule {} export class AppModule {}
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { Redlock } from '@sesamecare-oss/redlock'; // import { Redlock } from '@sesamecare-oss/redlock';
import { ConfigService } from '@nestjs/config'; import { ConfigService } from '@nestjs/config';
import Redis from 'ioredis'; import Redis from 'ioredis';
......
...@@ -46,8 +46,7 @@ export class MirrorService extends ConsoleLogger implements OnApplicationBootstr ...@@ -46,8 +46,7 @@ export class MirrorService extends ConsoleLogger implements OnApplicationBootstr
private db: Connection, private db: Connection,
private config: ConfigService, private config: ConfigService,
private http: HttpService, private http: HttpService,
private packageS3: PackageS3Service, private packageS3: PackageS3Service // private redlock: LockService
// private redlock: LockService
) { ) {
super('mirror'); super('mirror');
} }
......
...@@ -205,7 +205,6 @@ export class PackagerService extends ConsoleLogger { ...@@ -205,7 +205,6 @@ export class PackagerService extends ConsoleLogger {
async checksum(root: string, directories: string[], files: string[]): Promise<Record<string, string>> { async checksum(root: string, directories: string[], files: string[]): Promise<Record<string, string>> {
// 通常系统参数限制在 128KB 左右,保守一点设为 32KB // 通常系统参数限制在 128KB 左右,保守一点设为 32KB
function chunkFiles(files: string[], limit = ARG_SIZE_LIMIT): string[][] { function chunkFiles(files: string[], limit = ARG_SIZE_LIMIT): string[][] {
const chunks: string[][] = []; const chunks: string[][] = [];
let currentChunk: string[] = []; let currentChunk: string[] = [];
...@@ -232,24 +231,22 @@ export class PackagerService extends ConsoleLogger { ...@@ -232,24 +231,22 @@ export class PackagerService extends ConsoleLogger {
const fileChunks = chunkFiles(files); const fileChunks = chunkFiles(files);
const chunkPromises = fileChunks.map((chunk) => const chunkPromises = fileChunks.map((chunk) =>
util.promisify(child_process.execFile)('sha256sum', chunk, { util
cwd: root, .promisify(child_process.execFile)('sha256sum', chunk, {
maxBuffer: 1 * 1024 ** 3, cwd: root,
}).then(({ stdout }) => maxBuffer: 1 * 1024 ** 3,
stdout })
.trim() .then(({ stdout }) =>
.split('\n') stdout
.map((line) => line.split(' ', 2).reverse()) .trim()
) .split('\n')
.map((line) => line.split(' ', 2).reverse())
)
); );
const results = (await Promise.all(chunkPromises)).flat(); const results = (await Promise.all(chunkPromises)).flat();
return Object.fromEntries([ return Object.fromEntries([['.', ''], ...directories.map((d) => [d, '']), ...results]);
['.', ''],
...directories.map((d) => [d, '']),
...results,
]);
} }
private lock = new BetterLock(); private lock = new BetterLock();
...@@ -330,10 +327,10 @@ export class PackagerService extends ConsoleLogger { ...@@ -330,10 +327,10 @@ export class PackagerService extends ConsoleLogger {
hashObject.update(chunk); hashObject.update(chunk);
}); });
let uploadStream = child.stdout; const uploadStream = child.stdout;
try { try {
/* if (files.length > 1000) { /* if (files.length > 1000) {
this.warn(`Too many files in archive ${archiveName}, using tmp file.`); this.warn(`Too many files in archive ${archiveName}, using tmp file.`);
// minio would skew the stream if it's too slow // minio would skew the stream if it's too slow
......
...@@ -63,34 +63,34 @@ export class S3Service extends ConsoleLogger { ...@@ -63,34 +63,34 @@ export class S3Service extends ConsoleLogger {
return this.s3.send(command); return this.s3.send(command);
} }
async removeObjects(paths: string[]) { async removeObjects(paths: string[]) {
const CHUNK_SIZE = 1000; const CHUNK_SIZE = 1000;
// 分块 // 分块
const chunks: string[][] = []; const chunks: string[][] = [];
for (let i = 0; i < paths.length; i += CHUNK_SIZE) { for (let i = 0; i < paths.length; i += CHUNK_SIZE) {
chunks.push(paths.slice(i, i + CHUNK_SIZE)); chunks.push(paths.slice(i, i + CHUNK_SIZE));
} }
// 构造所有 delete 命令的 promise
const deletePromises = chunks.map((chunk) => {
const command = new DeleteObjectsCommand({
Bucket: this.bucket,
Delete: {
Objects: chunk.map((path) => ({
Key: this.getPathWithPrefix(path),
})),
},
});
return this.s3.send(command).catch((e) => { // 构造所有 delete 命令的 promise
this.error(`Failed to remove ${chunk.length} S3 objects: ${e}`); const deletePromises = chunks.map((chunk) => {
const command = new DeleteObjectsCommand({
Bucket: this.bucket,
Delete: {
Objects: chunk.map((path) => ({
Key: this.getPathWithPrefix(path),
})),
},
});
return this.s3.send(command).catch((e) => {
this.error(`Failed to remove ${chunk.length} S3 objects: ${e}`);
});
}); });
});
// 并发执行全部请求 // 并发执行全部请求
await Promise.all(deletePromises); await Promise.all(deletePromises);
} }
async fileExists(path: string) { async fileExists(path: string) {
// const objects = await this.listObjects(path); // const objects = await this.listObjects(path);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment