Optimize homepage videos query
This commit is contained in:
parent
1e3fd73cdf
commit
92fb7a2b62
|
@ -1,11 +1,12 @@
|
|||
import { finalize } from 'rxjs/operators'
|
||||
import { finalize, map } from 'rxjs/operators'
|
||||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
|
||||
import { AuthService, Notifier } from '@app/core'
|
||||
import { objectKeysTyped } from '@peertube/peertube-core-utils'
|
||||
import { VideoSortField } from '@peertube/peertube-models'
|
||||
import { ResultList, VideoSortField } from '@peertube/peertube-models'
|
||||
import { Video, VideoService } from '../../shared-main'
|
||||
import { MiniatureDisplayOptions } from '../../shared-video-miniature'
|
||||
import { CustomMarkupComponent } from './shared'
|
||||
import { Observable } from 'rxjs'
|
||||
|
||||
/*
|
||||
* Markup component list videos depending on criteria
|
||||
|
@ -75,7 +76,7 @@ export class VideosListMarkupComponent implements CustomMarkupComponent, OnInit
|
|||
return this.getVideosObservable()
|
||||
.pipe(finalize(() => this.loaded.emit(true)))
|
||||
.subscribe({
|
||||
next: ({ data }) => {
|
||||
next: data => {
|
||||
this.videos = data
|
||||
this.cd.markForCheck()
|
||||
},
|
||||
|
@ -96,12 +97,16 @@ export class VideosListMarkupComponent implements CustomMarkupComponent, OnInit
|
|||
isLive: this.isLive,
|
||||
sort: this.sort as VideoSortField,
|
||||
account: { nameWithHost: this.accountHandle },
|
||||
videoChannel: { nameWithHost: this.channelHandle }
|
||||
videoChannel: { nameWithHost: this.channelHandle },
|
||||
skipCount: true
|
||||
}
|
||||
|
||||
if (this.channelHandle) return this.videoService.getVideoChannelVideos(options)
|
||||
if (this.accountHandle) return this.videoService.getAccountVideos(options)
|
||||
let obs: Observable<ResultList<Video>>
|
||||
|
||||
return this.videoService.getVideos(options)
|
||||
if (this.channelHandle) obs = this.videoService.getVideoChannelVideos(options)
|
||||
else if (this.accountHandle) obs = this.videoService.getAccountVideos(options)
|
||||
else obs = this.videoService.getVideos(options)
|
||||
|
||||
return obs.pipe(map(({ data }) => data))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ import { Observable, Subject } from 'rxjs'
|
|||
import { filter, first, map } from 'rxjs/operators'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { buildBulkObservable } from '@app/helpers'
|
||||
import { ResultList } from '@peertube/peertube-models'
|
||||
import { Video, VideoChannel } from '../shared-main'
|
||||
import { VideoPlaylist } from '../shared-video-playlist'
|
||||
import { AdvancedSearch } from './advanced-search.model'
|
||||
|
@ -21,9 +20,9 @@ export class FindInBulkService {
|
|||
|
||||
private advancedSearchForBulk: AdvancedSearch
|
||||
|
||||
private getVideoInBulk: BulkObservables<string, ResultList<Video>>
|
||||
private getChannelInBulk: BulkObservables<string, ResultList<VideoChannel>>
|
||||
private getPlaylistInBulk: BulkObservables<string, ResultList<VideoPlaylist>>
|
||||
private getVideoInBulk: BulkObservables<string, { data: Video[] }>
|
||||
private getChannelInBulk: BulkObservables<string, { data: VideoChannel[] }>
|
||||
private getPlaylistInBulk: BulkObservables<string, { data: VideoPlaylist[] }>
|
||||
|
||||
constructor (
|
||||
private searchService: SearchService
|
||||
|
@ -66,7 +65,7 @@ export class FindInBulkService {
|
|||
}
|
||||
|
||||
private getData <P extends number | string, R> (options: {
|
||||
observableObject: BulkObservables<P, ResultList<R>>
|
||||
observableObject: BulkObservables<P, { data: R[] }>
|
||||
param: P
|
||||
finder: (d: R) => boolean
|
||||
}) {
|
||||
|
@ -104,6 +103,7 @@ export class FindInBulkService {
|
|||
return this.searchService.searchVideos({
|
||||
uuids,
|
||||
componentPagination: { itemsPerPage: uuids.length, currentPage: 1 },
|
||||
skipCount: true,
|
||||
advancedSearch: this.advancedSearchForBulk
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue