optimize show filter

This commit is contained in:
2026-03-09 18:29:56 +01:00
parent 194f9ac556
commit 36e1241539
5 changed files with 45 additions and 13 deletions

View File

@@ -3,6 +3,8 @@ import {Observable} from 'rxjs';
import {DbService} from '../../../services/db.service';
import {Show} from './show';
import {map, shareReplay} from 'rxjs/operators';
import {QueryFn} from '@angular/fire/compat/firestore/interfaces';
import firebase from 'firebase/compat/app';
@Injectable({
providedIn: 'root',
@@ -22,6 +24,23 @@ export class ShowDataService {
public listRaw$ = () => this.dbService.col$<Show>(this.collection);
public listPublicSince$(lastMonths: number): Observable<Show[]> {
const startDate = new Date();
startDate.setHours(0, 0, 0, 0);
startDate.setDate(startDate.getDate() - lastMonths * 30);
const startTimestamp = firebase.firestore.Timestamp.fromDate(startDate);
const queryFn: QueryFn = ref => ref.where('published', '==', true).where('date', '>=', startTimestamp).orderBy('date', 'desc');
return this.dbService.col$<Show>(this.collection, queryFn).pipe(
map(shows => shows.filter(show => !show.archived)),
shareReplay({
bufferSize: 1,
refCount: true,
})
);
}
public read$ = (showId: string): Observable<Show | null> => this.dbService.doc$(`${this.collection}/${showId}`);
public update = async (showId: string, data: Partial<Show>): Promise<void> => await this.dbService.doc(`${this.collection}/${showId}`).update(data);