mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-08 17:06:15 -08:00
fix(electron): isolate refresh performance correlation
This commit is contained in:
1 parent
e3ce60a35e
commit
f9e71a6d8d
25 files changed
+728
-402
No files matched your search
@@ -1336,6 +1336,37 @@ describe('PlaylistsService', () => {
|
||||
expect(electron.dbUpsertAppPlaylist).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('forwards refresh instrumentation only to its SQLite read and write', async () => {
|
||||
const { electron } = createStatefulElectronStore(
|
||||
createBasePlaylist('playlist-instrumented-refresh')
|
||||
);
|
||||
testWindow.electron = electron;
|
||||
const service = createService();
|
||||
const operationId = 'playlist-refresh-operation';
|
||||
|
||||
await firstValueFrom(
|
||||
service.updatePlaylist(
|
||||
'playlist-instrumented-refresh',
|
||||
{
|
||||
_id: 'playlist-instrumented-refresh',
|
||||
playlist: { items: [] },
|
||||
} as Playlist,
|
||||
operationId
|
||||
)
|
||||
);
|
||||
|
||||
expect(electron.dbGetAppPlaylist).toHaveBeenCalledWith(
|
||||
'playlist-instrumented-refresh',
|
||||
operationId
|
||||
);
|
||||
expect(electron.dbUpsertAppPlaylist).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
_id: 'playlist-instrumented-refresh',
|
||||
}),
|
||||
operationId
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps both favorites when two rapid favorite adds overlap (SQLite)', async () => {
|
||||
const { store, electron } = createStatefulElectronStore(
|
||||
createBasePlaylist('portal-race-two-favorites')
|
||||
|
||||
@@ -52,7 +52,10 @@ type PlaylistRawItem = {
|
||||
type PlaylistStorageElectronApi = {
|
||||
dbDeleteAllPlaylists: () => Promise<unknown>;
|
||||
dbDeletePlaylist: (playlistId: string) => Promise<unknown>;
|
||||
dbGetAppPlaylist: (playlistId: string) => Promise<Playlist | null>;
|
||||
dbGetAppPlaylist: (
|
||||
playlistId: string,
|
||||
operationId?: string
|
||||
) => Promise<Playlist | null>;
|
||||
dbGetAppPlaylistFavoriteChannels?: (
|
||||
playlistId: string
|
||||
) => Promise<M3uFavoriteChannel[]>;
|
||||
@@ -60,7 +63,10 @@ type PlaylistStorageElectronApi = {
|
||||
dbGetAppPlaylists: () => Promise<Playlist[]>;
|
||||
dbGetAppState: (key: string) => Promise<string | null>;
|
||||
dbSetAppState: (key: string, value: string) => Promise<unknown>;
|
||||
dbUpsertAppPlaylist: (playlist: Playlist) => Promise<unknown>;
|
||||
dbUpsertAppPlaylist: (
|
||||
playlist: Playlist,
|
||||
operationId?: string
|
||||
) => Promise<unknown>;
|
||||
dbUpsertAppPlaylists: (playlists: Playlist[]) => Promise<unknown>;
|
||||
};
|
||||
|
||||
@@ -362,14 +368,18 @@ export class PlaylistsService {
|
||||
}
|
||||
}
|
||||
|
||||
private upsertSqlitePlaylist(playlist: Playlist) {
|
||||
private upsertSqlitePlaylist(playlist: Playlist, operationId?: string) {
|
||||
return this.runOnSqlite(async () => {
|
||||
const electron = this.electronApi;
|
||||
if (!electron) {
|
||||
return playlist;
|
||||
}
|
||||
|
||||
await electron.dbUpsertAppPlaylist(playlist);
|
||||
if (operationId === undefined) {
|
||||
await electron.dbUpsertAppPlaylist(playlist);
|
||||
} else {
|
||||
await electron.dbUpsertAppPlaylist(playlist, operationId);
|
||||
}
|
||||
return playlist;
|
||||
});
|
||||
}
|
||||
@@ -411,9 +421,14 @@ export class PlaylistsService {
|
||||
});
|
||||
}
|
||||
|
||||
private persistPlaylistMutation(nextPlaylist: Playlist) {
|
||||
private persistPlaylistMutation(
|
||||
nextPlaylist: Playlist,
|
||||
operationId?: string
|
||||
) {
|
||||
if (this.isElectronStorageAvailable) {
|
||||
return firstValueFrom(this.upsertSqlitePlaylist(nextPlaylist));
|
||||
return firstValueFrom(
|
||||
this.upsertSqlitePlaylist(nextPlaylist, operationId)
|
||||
);
|
||||
}
|
||||
|
||||
return firstValueFrom(
|
||||
@@ -554,10 +569,14 @@ export class PlaylistsService {
|
||||
};
|
||||
}
|
||||
|
||||
updatePlaylist(playlistId: string, updatedPlaylist: Playlist) {
|
||||
updatePlaylist(
|
||||
playlistId: string,
|
||||
updatedPlaylist: Playlist,
|
||||
operationId?: string
|
||||
) {
|
||||
return this.serializePlaylistWrite(playlistId, async () => {
|
||||
const currentPlaylist = await firstValueFrom(
|
||||
this.getPlaylistById(playlistId)
|
||||
this.getPlaylistById(playlistId, operationId)
|
||||
);
|
||||
const mergedPlaylist = this.mergeRefreshedPlaylist(
|
||||
currentPlaylist,
|
||||
@@ -565,17 +584,21 @@ export class PlaylistsService {
|
||||
playlistId
|
||||
);
|
||||
|
||||
return this.persistPlaylistMutation(mergedPlaylist);
|
||||
return this.persistPlaylistMutation(mergedPlaylist, operationId);
|
||||
});
|
||||
}
|
||||
|
||||
getPlaylistById(id: string) {
|
||||
getPlaylistById(id: string, operationId?: string) {
|
||||
if (this.isElectronStorageAvailable) {
|
||||
return this.runOnSqlite(async () => {
|
||||
const electron = this.electronApi;
|
||||
const playlist = electron
|
||||
? await electron.dbGetAppPlaylist(id)
|
||||
: null;
|
||||
let playlist: Playlist | null = null;
|
||||
if (electron) {
|
||||
playlist =
|
||||
operationId === undefined
|
||||
? await electron.dbGetAppPlaylist(id)
|
||||
: await electron.dbGetAppPlaylist(id, operationId);
|
||||
}
|
||||
return playlist
|
||||
? this.createSqliteFallbackPlaylist(playlist as Playlist)
|
||||
: (undefined as unknown as Playlist);
|
||||
|
||||
Reference in new issue
Block a user