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