optimize firebase reads

This commit is contained in:
2026-03-09 17:41:24 +01:00
parent 4141824b00
commit d81fb3743b
10 changed files with 136 additions and 49 deletions

View File

@@ -56,6 +56,7 @@ export class SongComponent implements OnInit {
public song$: Observable<Song | null> | null = null;
public files$: Observable<File[] | null> | null = null;
public user$: Observable<User | null> | null = null;
public songCount$: Observable<number> | null = null;
public faEdit = faEdit;
public faDelete = faTrash;
public faFileCirclePlus = faFileCirclePlus;
@@ -85,6 +86,17 @@ export class SongComponent implements OnInit {
map(param => param.songId),
switchMap(songId => this.fileService.read$(songId))
);
this.songCount$ = combineLatest([this.user$, this.song$]).pipe(
map(([user, song]) => {
if (!song) {
return 0;
}
return user?.songUsage?.[song.id] ?? 0;
}),
distinctUntilChanged()
);
}
public getFlags = (flags: string): string[] => {
@@ -105,12 +117,4 @@ export class SongComponent implements OnInit {
await this.showService.update$(show?.id, {order: [...show.order, newId ?? '']});
await this.router.navigateByUrl('/shows/' + show.id);
}
public songCount$ = () =>
combineLatest([this.user$, this.song$]).pipe(
map(([user, song]) => {
return user.songUsage[song.id];
}),
distinctUntilChanged()
);
}