Skip to content

Commit a27e809

Browse files
committed
Limit main pages to 24h posts
1 parent 1c5fd0f commit a27e809

File tree

2 files changed

+24
-37
lines changed

2 files changed

+24
-37
lines changed

app/api/user-submissions/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ export async function GET(request: NextRequest) {
4545
)
4646
}
4747

48-
// Fetch posts by the current user with pagination
48+
// Fetch posts by the current user with pagination (only from last 24 hours)
4949
const posts = await databases.listDocuments(
5050
process.env.APPWRITE_DATABASE_ID || '',
5151
process.env.APPWRITE_POSTS_COLLECTION_ID || '',
5252
[
5353
Query.equal('userId', user.$id),
54+
Query.greaterThan('$createdAt', new Date(Date.now() - (24 * 60 * 60 * 1000)).toISOString()), // Only show posts from last 24 hours
5455
Query.orderDesc('$createdAt'),
5556
Query.limit(limit),
5657
Query.offset(offset),

lib/data.ts

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -365,28 +365,26 @@ export async function fetchPostsFromAppwriteWithSort(sortType: 'score' | 'new' |
365365

366366
let queries = []
367367

368+
// Always filter posts to only show those from the last 24 hours
369+
const twentyFourHoursAgo = getTwentyFourHoursAgo()
370+
queries.push(Query.greaterThan('$createdAt', twentyFourHoursAgo))
371+
368372
// Apply different sorting based on sortType
369373
switch (sortType) {
370374
case 'score':
371375
// Sort by count (total score) - highest first, then by creation date
372-
queries = [
373-
Query.orderDesc('score'),
374-
Query.orderDesc('$createdAt')
375-
]
376+
queries.push(Query.orderDesc('score'))
377+
queries.push(Query.orderDesc('$createdAt'))
376378
break
377379
case 'new':
378380
// Sort by creation date - newest first
379-
queries = [
380-
Query.orderDesc('$createdAt')
381-
]
381+
queries.push(Query.orderDesc('$createdAt'))
382382
break
383383
case 'show':
384384
// Filter by type=show, sort by count first, then by creation date
385-
queries = [
386-
Query.equal('type', 'show'),
387-
Query.orderDesc('score'),
388-
Query.orderDesc('$createdAt')
389-
]
385+
queries.push(Query.equal('type', 'show'))
386+
queries.push(Query.orderDesc('score'))
387+
queries.push(Query.orderDesc('$createdAt'))
390388
break
391389
}
392390

@@ -801,24 +799,18 @@ export async function fetchPostsFromAppwriteWithSortAndVotes(
801799
switch (sortType) {
802800
case 'score':
803801
// Sort by count (total score) - highest first, then by creation date
804-
queries = [
805-
Query.orderDesc('score'),
806-
Query.orderDesc('$createdAt')
807-
]
802+
queries.push(Query.orderDesc('score'))
803+
queries.push(Query.orderDesc('$createdAt'))
808804
break
809805
case 'new':
810806
// Sort by creation date - newest first
811-
queries = [
812-
Query.orderDesc('$createdAt')
813-
]
807+
queries.push(Query.orderDesc('$createdAt'))
814808
break
815809
case 'show':
816810
// Filter by type=show, sort by score first, then by creation date
817-
queries = [
818-
Query.equal('type', 'show'),
819-
Query.orderDesc('score'),
820-
Query.orderDesc('$createdAt')
821-
]
811+
queries.push(Query.equal('type', 'show'))
812+
queries.push(Query.orderDesc('score'))
813+
queries.push(Query.orderDesc('$createdAt'))
822814
break
823815
}
824816

@@ -1242,24 +1234,18 @@ export async function fetchPostsFromAppwriteWithCommentsAndVotes(
12421234
switch (sortType) {
12431235
case 'score':
12441236
// Sort by count (total score) - highest first, then by creation date
1245-
queries = [
1246-
Query.orderDesc('score'),
1247-
Query.orderDesc('$createdAt')
1248-
]
1237+
queries.push(Query.orderDesc('score'))
1238+
queries.push(Query.orderDesc('$createdAt'))
12491239
break
12501240
case 'new':
12511241
// Sort by creation date - newest first
1252-
queries = [
1253-
Query.orderDesc('$createdAt')
1254-
]
1242+
queries.push(Query.orderDesc('$createdAt'))
12551243
break
12561244
case 'show':
12571245
// Filter by type=show, sort by score first, then by creation date
1258-
queries = [
1259-
Query.equal('type', 'show'),
1260-
Query.orderDesc('score'),
1261-
Query.orderDesc('$createdAt')
1262-
]
1246+
queries.push(Query.equal('type', 'show'))
1247+
queries.push(Query.orderDesc('score'))
1248+
queries.push(Query.orderDesc('$createdAt'))
12631249
break
12641250
}
12651251

0 commit comments

Comments
 (0)