@@ -187,6 +187,52 @@ public async Task<PaginationOfT<VideoInfoModel>> GetPaginatedCompletedVideoInfob
187
187
return result ;
188
188
}
189
189
190
+ public async Task < PaginationOfT < VideoInfoModel > > GetSmallPaginatedCompletedVideoInfoAsync (
191
+ PaginationRequest paginationRequest , string ? searchTerm ,
192
+ CancellationToken cancellationToken
193
+ )
194
+ {
195
+ PaginationOfT < VideoInfoModel > result = new ( ) ;
196
+ var dbContext = await dbContextFactory . CreateDbContextAsync ( cancellationToken ) ;
197
+ string orderByString = string . Empty ;
198
+ if ( paginationRequest . SortingItems ? . Length > 0 )
199
+ orderByString =
200
+ String . Join ( "," ,
201
+ paginationRequest . SortingItems . Select ( p => $ "{ p . PropertyName } { GetSortTypeString ( p . SortType ) } ") ) ;
202
+ var preQuery = dbContext . VideoInfo
203
+ . AsNoTracking ( )
204
+ . AsSplitQuery ( ) ;
205
+ if ( ! String . IsNullOrWhiteSpace ( searchTerm ) )
206
+ {
207
+ preQuery =
208
+ preQuery . Where ( p => EF . Functions . FreeText ( p . Description , searchTerm ! ) ) ;
209
+ }
210
+ var query = preQuery
211
+ . Where ( p =>
212
+ p . VideoIndexStatusId == ( short ) FairPlayCombined . Common . FairPlayTube . Enums . VideoIndexStatus . Processed )
213
+ . Select ( p => new VideoInfoModel
214
+ {
215
+ VideoInfoId = p . VideoInfoId ,
216
+ VideoId = p . VideoId ,
217
+ Name = p . Name ,
218
+ Description = p . Description ,
219
+ LifetimeViewers = p . VideoWatchTime . Select ( p => p . WatchedByApplicationUserId ) . Distinct ( ) . Count ( ) ,
220
+ LifetimeSessions = p . VideoWatchTime . Count ,
221
+ LifetimeWatchTime = TimeSpan . FromSeconds ( p . VideoWatchTime . Sum ( p => p . WatchTime ) ) ,
222
+ PublishedOnString = ( DateTimeOffset . UtcNow . Subtract ( p . RowCreationDateTime ) . TotalDays < 1 ? "Today" : $ "{ DateTimeOffset . UtcNow . Subtract ( p . RowCreationDateTime ) . Days } { localizer ! [ DaysAgoTextKey ] } ")
223
+ } ) ;
224
+ if ( ! String . IsNullOrEmpty ( orderByString ) )
225
+ query = query . OrderBy ( orderByString ) ;
226
+ result . TotalItems = await query . CountAsync ( cancellationToken ) ;
227
+ result . PageSize = paginationRequest . PageSize ;
228
+ result . TotalPages = ( int ) Math . Ceiling ( ( decimal ) result . TotalItems / result . PageSize ) ;
229
+ result . Items = await query
230
+ . Skip ( paginationRequest . StartIndex )
231
+ . Take ( paginationRequest . PageSize )
232
+ . ToArrayAsync ( cancellationToken ) ;
233
+ return result ;
234
+ }
235
+
190
236
public async Task < PaginationOfT < VideoInfoModel > > GetPaginatedCompletedVideoInfoAsync (
191
237
PaginationRequest paginationRequest , string ? searchTerm ,
192
238
CancellationToken cancellationToken
0 commit comments