add log + use allSettled

This commit is contained in:
MathieuG-P
2023-03-01 23:26:48 +01:00
parent 363cc3cc5e
commit a56fdde0e7
5 changed files with 12 additions and 9 deletions
+2
View File
@@ -3,6 +3,7 @@ import { UtilsService } from "../services/utils.service";
import { IpcRequest } from "shared/models/ipc";
import { SearchParams } from "shared/models/maps/beat-saver.model";
import { BeatSaverService } from "../services/thrid-party/beat-saver/beat-saver.service";
import log from "electron-log";
ipcMain.on("bsv-search-map", async (event, request: IpcRequest<SearchParams>) => {
const utlis = UtilsService.getInstance();
@@ -22,6 +23,7 @@ ipcMain.on("bsv-get-map-details-from-hashs", async (event, request: IpcRequest<s
bsvService.getMapDetailsFromHashs(request.args).then(maps => {
utlis.ipcSend(request.responceChannel, {success: true, data: maps});
}).catch(e => {
log.error(e);
utlis.ipcSend(request.responceChannel, {success: false, error: e});
})
});
@@ -135,8 +135,6 @@ export class LocalMapsManagerService {
return new Observable<BsmLocalMapsProgress>(observer => {
(async () => {
console.time()
const levelsFolder = await this.getMapsFolderPath(version);
const levelsPaths = (await this.utils.pathExist(levelsFolder)) ? this.utils.listDirsInDir(levelsFolder, true) : [];
@@ -151,14 +149,18 @@ export class LocalMapsManagerService {
return mapInfo;
});
const mapsInfo = (await Promise.all(promises)).filter(info => info);
const mapsInfo = (await Promise.allSettled(promises)).reduce((acc, mapInfo) => {
if(mapInfo.status === "fulfilled" && mapInfo.value){
acc.push(mapInfo.value);
}
return acc;
} ,[] as BsmLocalMap[]);
progression.maps = mapsInfo;
observer.next(progression);
observer.complete();
console.timeEnd();
})();
});
}
-1
View File
@@ -47,7 +47,6 @@ export class IpcService {
observable.subscribe(data => {
this.send(channel, window, data);
}, error => {
console.log("LAAAA 2", error);
this.send(this.getErrorChannel(channel), window, error);
}, () => {
this.send(this.getCompleteChannel(channel), window);
@@ -32,7 +32,7 @@ export class BeatSaverService {
return res;
}, [] as BsvMapDetail[]);
await Promise.all(chunkHash.map(async hashs => {
await Promise.allSettled(chunkHash.map(async hashs => {
const res = await this.bsaverApi.getMapsDetailsByHashs(hashs);
if(res.status === 200){
@@ -17,8 +17,8 @@ export class BeatSaverService {
}
public async getMapDetailsFromHashs(hashs: string[]): Promise<BsvMapDetail[]>{
//const res = await this.ipc.send<BsvMapDetail[], string[]>("bsv-get-map-details-from-hashs", {args: hashs});
return [];
const res = await this.ipc.send<BsvMapDetail[], string[]>("bsv-get-map-details-from-hashs", {args: hashs});
return res.data ?? [];
}