diff --git a/client/src/app/+videos/+video-watch/shared/recommendations/recent-videos-recommendation.service.ts b/client/src/app/+videos/+video-watch/shared/recommendations/recent-videos-recommendation.service.ts index 174fd6610..a965f64c2 100644 --- a/client/src/app/+videos/+video-watch/shared/recommendations/recent-videos-recommendation.service.ts +++ b/client/src/app/+videos/+video-watch/shared/recommendations/recent-videos-recommendation.service.ts @@ -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', diff --git a/client/src/app/shared/shared-search/search.service.ts b/client/src/app/shared/shared-search/search.service.ts index 281e0b4bd..301e857cc 100644 --- a/client/src/app/shared/shared-search/search.service.ts +++ b/client/src/app/shared/shared-search/search.service.ts @@ -31,8 +31,9 @@ export class SearchService { componentPagination?: ComponentPaginationLight advancedSearch?: AdvancedSearch uuids?: string[] + skipCount?: boolean }): Observable> { - 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) { diff --git a/server/core/controllers/api/search/search-videos.ts b/server/core/controllers/api/search/search-videos.ts index a6700ed7d..e3be237af 100644 --- a/server/core/controllers/api/search/search-videos.ts +++ b/server/core/controllers/api/search/search-videos.ts @@ -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 diff --git a/server/core/models/video/video.ts b/server/core/models/video/video.ts index d513a1ee3..71a3f93fb 100644 --- a/server/core/models/video/video.ts +++ b/server/core/models/video/video.ts @@ -1241,6 +1241,8 @@ export class VideoModel extends Model>> { 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>> { serverAccountIdForBlock: serverActor.Account.id } - return VideoModel.getAvailableForApi(queryOptions) + return VideoModel.getAvailableForApi(queryOptions, options.countVideos) } static countLives (options: {