|
@@ -8,14 +8,13 @@ import {
|
|
AllChannelFieldsFragment,
|
|
AllChannelFieldsFragment,
|
|
AssetAvailability,
|
|
AssetAvailability,
|
|
GetVideosConnectionQueryVariables,
|
|
GetVideosConnectionQueryVariables,
|
|
- GetVideosQueryVariables,
|
|
|
|
Query,
|
|
Query,
|
|
VideoConnection,
|
|
VideoConnection,
|
|
VideoFieldsFragment,
|
|
VideoFieldsFragment,
|
|
VideoOrderByInput,
|
|
VideoOrderByInput,
|
|
} from '../queries'
|
|
} from '../queries'
|
|
|
|
|
|
-const getVideoKeyArgs = (args: Record<string, GetVideosQueryVariables['where']> | null) => {
|
|
|
|
|
|
+const getVideoKeyArgs = (args: GetVideosConnectionQueryVariables | null) => {
|
|
// make sure queries asking for a specific category are separated in cache
|
|
// make sure queries asking for a specific category are separated in cache
|
|
const onlyCount = args?.first === 0
|
|
const onlyCount = args?.first === 0
|
|
const channelId = args?.where?.channelId_eq || ''
|
|
const channelId = args?.where?.channelId_eq || ''
|
|
@@ -24,13 +23,14 @@ const getVideoKeyArgs = (args: Record<string, GetVideosQueryVariables['where']>
|
|
const isPublic = args?.where?.isPublic_eq ?? ''
|
|
const isPublic = args?.where?.isPublic_eq ?? ''
|
|
const channelIdIn = args?.where?.channelId_in ? JSON.stringify(args.where.channelId_in) : ''
|
|
const channelIdIn = args?.where?.channelId_in ? JSON.stringify(args.where.channelId_in) : ''
|
|
const createdAtGte = args?.where?.createdAt_gte ? JSON.stringify(args.where.createdAt_gte) : ''
|
|
const createdAtGte = args?.where?.createdAt_gte ? JSON.stringify(args.where.createdAt_gte) : ''
|
|
|
|
+ const sorting = args?.orderBy?.[0] ? args.orderBy[0] : ''
|
|
|
|
|
|
// only for counting videos in HomeView
|
|
// only for counting videos in HomeView
|
|
if (args?.where?.channelId_in && !args?.first) {
|
|
if (args?.where?.channelId_in && !args?.first) {
|
|
return `${createdAtGte}:${channelIdIn}`
|
|
return `${createdAtGte}:${channelIdIn}`
|
|
}
|
|
}
|
|
|
|
|
|
- return `${onlyCount}:${channelId}:${categoryId}:${channelIdIn}:${createdAtGte}:${isPublic}:${idEq}`
|
|
|
|
|
|
+ return `${onlyCount}:${channelId}:${categoryId}:${channelIdIn}:${createdAtGte}:${isPublic}:${idEq}:${sorting}`
|
|
}
|
|
}
|
|
|
|
|
|
const createDateHandler = () => ({
|
|
const createDateHandler = () => ({
|
|
@@ -97,13 +97,10 @@ const queryCacheFields: CachePolicyFields<keyof Query> = {
|
|
const filteredEdges =
|
|
const filteredEdges =
|
|
existing?.edges.filter((edge) => readField('isPublic', edge.node) === isPublic || isPublic === undefined) ?? []
|
|
existing?.edges.filter((edge) => readField('isPublic', edge.node) === isPublic || isPublic === undefined) ?? []
|
|
|
|
|
|
- const sortingASC = args?.orderBy === VideoOrderByInput.CreatedAtAsc
|
|
|
|
- const preSortedDESC = (filteredEdges || [])
|
|
|
|
- .slice()
|
|
|
|
- .sort(
|
|
|
|
- (a, b) =>
|
|
|
|
- (readField('createdAt', b.node) as Date).getTime() - (readField('createdAt', a.node) as Date).getTime()
|
|
|
|
- )
|
|
|
|
|
|
+ const sortingASC = args?.orderBy?.[0] === VideoOrderByInput.CreatedAtAsc
|
|
|
|
+ const preSortedDESC = (filteredEdges || []).slice().sort((a, b) => {
|
|
|
|
+ return (readField('createdAt', b.node) as Date).getTime() - (readField('createdAt', a.node) as Date).getTime()
|
|
|
|
+ })
|
|
const sortedEdges = sortingASC ? preSortedDESC.reverse() : preSortedDESC
|
|
const sortedEdges = sortingASC ? preSortedDESC.reverse() : preSortedDESC
|
|
|
|
|
|
return (
|
|
return (
|