1
0
Fork 0

Skip counting for recommended videos

This commit is contained in:
Chocobozzz 2023-10-25 14:53:53 +02:00
parent cb38deb288
commit 360439088d
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 12 additions and 5 deletions

View File

@ -61,6 +61,7 @@ export class RecentVideosRecommendationService implements RecommendationService
return this.searchService.searchVideos({
search: '',
componentPagination: pagination,
skipCount: true,
advancedSearch: new AdvancedSearch({
tagsOneOf: recommendation.tags.join(','),
sort: '-publishedAt',

View File

@ -31,8 +31,9 @@ export class SearchService {
componentPagination?: ComponentPaginationLight
advancedSearch?: AdvancedSearch
uuids?: string[]
skipCount?: boolean
}): Observable<ResultList<Video>> {
const { search, uuids, componentPagination, advancedSearch } = parameters
const { search, uuids, componentPagination, advancedSearch, skipCount } = parameters
if (advancedSearch?.resultType !== undefined && advancedSearch.resultType !== 'videos') {
return of({ total: 0, data: [] })
@ -49,6 +50,7 @@ export class SearchService {
params = this.restService.addRestGetParams(params, pagination)
if (search) params = params.append('search', search)
if (skipCount === true) params = params.append('skipCount', true)
if (uuids) params = this.restService.addArrayParams(params, 'uuids', uuids)
if (advancedSearch) {

View File

@ -10,7 +10,7 @@ import { Hooks } from '@server/lib/plugins/hooks.js'
import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@server/lib/search.js'
import { getServerActor } from '@server/models/application/application.js'
import { HttpStatusCode, ResultList, Video, VideosSearchQueryAfterSanitize } from '@peertube/peertube-models'
import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils.js'
import { buildNSFWFilter, getCountVideos, isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils.js'
import { logger } from '../../../helpers/logger.js'
import { getFormattedObjects } from '../../../helpers/utils.js'
import {
@ -61,7 +61,7 @@ function searchVideos (req: express.Request, res: express.Response) {
return searchVideosIndex(query, res)
}
return searchVideosDB(query, res)
return searchVideosDB(query, req, res)
}
async function searchVideosIndex (query: VideosSearchQueryAfterSanitize, res: express.Response) {
@ -101,7 +101,7 @@ async function searchVideosIndex (query: VideosSearchQueryAfterSanitize, res: ex
}
}
async function searchVideosDB (query: VideosSearchQueryAfterSanitize, res: express.Response) {
async function searchVideosDB (query: VideosSearchQueryAfterSanitize, req: express.Request, res: express.Response) {
const serverActor = await getServerActor()
const apiOptions = await Hooks.wrapObject({
@ -112,6 +112,8 @@ async function searchVideosDB (query: VideosSearchQueryAfterSanitize, res: expre
orLocalVideos: true
},
countVideos: getCountVideos(req),
nsfw: buildNSFWFilter(res, query.nsfw),
user: res.locals.oauth
? res.locals.oauth.token.User

View File

@ -1241,6 +1241,8 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
uuids?: string[]
excludeAlreadyWatched?: boolean
countVideos?: boolean
}) {
VideoModel.throwIfPrivateIncludeWithoutUser(options.include, options.user)
VideoModel.throwIfPrivacyOneOfWithoutUser(options.privacyOneOf, options.user)
@ -1281,7 +1283,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
serverAccountIdForBlock: serverActor.Account.id
}
return VideoModel.getAvailableForApi(queryOptions)
return VideoModel.getAvailableForApi(queryOptions, options.countVideos)
}
static countLives (options: {