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

@@ -2,7 +2,7 @@ import {Injectable} from '@angular/core';
import {Song} from './song';
import {Observable} from 'rxjs';
import {DbService} from '../../../services/db.service';
import {map, shareReplay, startWith} from 'rxjs/operators';
import {shareReplay, startWith} from 'rxjs/operators';
@Injectable({
providedIn: 'root',
@@ -22,10 +22,7 @@ export class SongDataService {
// this.list$.subscribe();
}
// public list$ = (): Observable<Song[]> => this.dbService.col$(this.collection);
//public read$ = (songId: string): Observable<Song | null> => this.dbService.doc$(this.collection + '/' + songId);
public read$ = (songId: string): Observable<Song | null> => this.list$.pipe(map(_ => _.find(s => s.id === songId) || null));
public read$ = (songId: string): Observable<Song | null> => this.dbService.doc$(this.collection + '/' + songId);
public update$ = async (songId: string, data: Partial<Song>): Promise<void> => await this.dbService.doc(this.collection + '/' + songId).update(data);
public add = async (data: Partial<Song>): Promise<string> => (await this.dbService.col(this.collection).add(data)).id;
public delete = async (songId: string): Promise<void> => await this.dbService.doc(this.collection + '/' + songId).delete();