Skip to content

Commit

Permalink
Added a process to correct a bug when upgrading to v1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ranmd9a committed Jul 28, 2022
1 parent b7f675b commit 69a7f4f
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 8 deletions.
19 changes: 17 additions & 2 deletions src/components/services/ScannerStatusService.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
/>
</v-card-text>

<v-card-text v-else>
<p>
Please wait...
</p>
<v-progress-linear indeterminate :value="0" color="success" rounded />
</v-card-text>

<v-card-actions>
<v-spacer />
<v-btn v-if="!isScanning" text color="success" @click="scanAll()">
Expand Down Expand Up @@ -67,10 +74,11 @@ export default Vue.extend({
progress: { beatmap: new Progress(), playlist: new ProgressGroup() },
scanningBeatmap: false,
scanningPlaylist: false,
preparing: false,
}),
computed: {
isScanning(): boolean {
return this.scanningBeatmap || this.scanningPlaylist;
return this.scanningBeatmap || this.scanningPlaylist || this.preparing;
},
},
mounted(): void {
Expand All @@ -92,16 +100,23 @@ export default Vue.extend({
ScannerService.ScanAll(true); // 非同期
NotificationServiceScanner.notifyOnNextScan();
},
onStatusDialogRequestOpen(): void {
onStatusDialogRequestOpen(withPreparation: boolean = false): void {
this.dialog = true;
if (withPreparation) {
this.preparing = true;
}
this.updateProgressListener();
},
onScanningStateUpdate(): void {
this.scanningBeatmap = ScannerService.scanning.beatmap;
this.scanningPlaylist = ScannerService.scanning.playlist;
if (this.scanningBeatmap || this.scanningPlaylist) {
this.preparing = false;
}
},
onScanCompleted(): void {
this.dialog = false;
this.preparing = false;
ScannerService.beatmapProgress.offPlusOne(this.updateProgress);
ScannerService.playlistProgress.offPlusOne(this.updateProgress);
},
Expand Down
15 changes: 12 additions & 3 deletions src/libraries/app/UpgradeCheckerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import MigrateTo123 from "@/libraries/app/migration/MigrationVersion1.2.3";
import MigrateTo132 from "@/libraries/app/migration/MigrationVersion1.3.2";
import MigrateTo138 from "@/libraries/app/migration/MigrationVersion1.3.8";
import MigrateTo140 from "@/libraries/app/migration/MigrationVersion1.4.0";
import MigrateTo141 from "@/libraries/app/migration/MigrationVersion1.4.1";
import ScannerService from "../scanner/ScannerService";

export default class UpgradeCheckerService {
Expand Down Expand Up @@ -46,15 +47,23 @@ export default class UpgradeCheckerService {
ScannerService.requestDialogToBeOpened();
MigrateTo132(); // clear playlist cache
await MigrateTo138(); // set folderNameHash, updateDownloadDate
await MigrateTo140(); // remove beatsaver cache
await MigrateTo141(false); // reload beatsaver cache (skip clearing playlist cache)
} else if (semver.gt("1.3.8", previousVersion)) {
// previousVersion is under 1.3.8
ScannerService.requestDialogToBeOpened();
await MigrateTo138(); // set folderNameHash, updateDownloadDate
}

if (semver.gt("1.4.0", previousVersion)) {
await MigrateTo140(); // remove beatsaver cache
await MigrateTo141(true); // reload beatsaver cache, clear playlist cache
} else if (semver.gt("1.4.0", previousVersion)) {
// previousVersion is under 1.4.0
ScannerService.requestDialogToBeOpened(true);
await MigrateTo140(); // remove beatsaver cache
await MigrateTo141(true); // reload beatsaver cache, clear playlist cache
} else if (semver.gt("1.4.1", previousVersion)) {
// previousVersion is under 1.4.1
ScannerService.requestDialogToBeOpened(true);
await MigrateTo141(true); // reload beatsaver cache, clear playlist cache
}
}

Expand Down
65 changes: 65 additions & 0 deletions src/libraries/app/migration/MigrationVersion1.4.1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import store from "@/plugins/store";
import BeatsaverCachedLibrary from "@/libraries/beatmap/repo/BeatsaverCachedLibrary";
import BeatmapLibrary from "@/libraries/beatmap/BeatmapLibrary";
import {
BeatsaverKey,
toStrKey,
BeatsaverKeyType,
} from "@/libraries/beatmap/repo/BeatsaverKeyType";
import BeatsaverCacheManager from "@/libraries/beatmap/repo/BeatsaverCacheManager";
import { BeatsaverItem } from "@/libraries/beatmap/repo/BeatsaverItem";

async function ReloadBeatsaverCache() {
const beatmaps = BeatmapLibrary.GetAllValidMap();
const validCache = BeatsaverCachedLibrary.GetAllValid();
const invalidCache = BeatsaverCachedLibrary.GetAllInvalid();

const targetKeys: BeatsaverKey[] = [];
for (const beatmap of beatmaps) {
const hash = beatmap.hash?.toUpperCase();
if (hash == null) {
// eslint-disable-next-line no-continue
continue;
}
if (validCache.has(hash)) {
// eslint-disable-next-line no-continue
continue;
}

const beatsaverKey: BeatsaverKey = {
type: BeatsaverKeyType.Hash,
value: hash,
};
const keyStr = toStrKey(beatsaverKey);
if (!invalidCache.has(keyStr)) {
targetKeys.push(beatsaverKey);
}
}
if (targetKeys.length > 0) {
const notCachedItems: {
key: BeatsaverKey;
item: BeatsaverItem;
}[] = [];
for (const beatsaverKey of targetKeys) {
// eslint-disable-next-line no-await-in-loop
const item = await BeatsaverCacheManager.forceGetCacheBeatmap(
beatsaverKey,
true
);
console.log(item);
notCachedItems.push({ key: beatsaverKey, item });
}
BeatsaverCachedLibrary.AddAll(notCachedItems);
}
}

function ClearPlaylistCache() {
store.commit("playlist/SET_PLAYLISTS", []);
}

export default async (clearPlaylistCache: boolean) => {
await ReloadBeatsaverCache();
if (clearPlaylistCache) {
ClearPlaylistCache();
}
};
8 changes: 5 additions & 3 deletions src/libraries/scanner/ScannerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ export default class ScannerService {
}
}

public static requestDialogToBeOpened() {
this.eventEmitter.emit(ON_REQUEST_DIALOG_OPEN);
public static requestDialogToBeOpened(withPreparation: boolean = false) {
this.eventEmitter.emit(ON_REQUEST_DIALOG_OPEN, withPreparation);
}

public static onBeatmapScanCompleted(
Expand Down Expand Up @@ -254,7 +254,9 @@ export default class ScannerService {
this.eventEmitter.off(ON_SCAN_COMPLETED, callback);
}

public static onStatusDialogRequestOpen(callback: () => void) {
public static onStatusDialogRequestOpen(
callback: (withPreparation: boolean) => void
) {
this.eventEmitter.on(ON_REQUEST_DIALOG_OPEN, callback);
}

Expand Down

0 comments on commit 69a7f4f

Please sign in to comment.