@@ -20,6 +20,25 @@ import {
20
20
timelineItemTable ,
21
21
} from "./schema.ts" ;
22
22
23
+ export const FUTURE_TIMESTAMP_TOLERANCE = ( ( ) => {
24
+ const envValue = Deno . env . get ( "FUTURE_TIMESTAMP_TOLERANCE" ) ;
25
+ if ( ! envValue ) return 300000 ;
26
+
27
+ const parsed = parseInt ( envValue , 10 ) ;
28
+ if ( isNaN ( parsed ) || parsed < 0 ) {
29
+ console . warn (
30
+ `Invalid FUTURE_TIMESTAMP_TOLERANCE: "${ envValue } ", using default 300000` ,
31
+ ) ;
32
+ return 300000 ;
33
+ }
34
+
35
+ return parsed ;
36
+ } ) ( ) ;
37
+
38
+ function getFutureTimestampLimit ( ) : Date {
39
+ return new Date ( Date . now ( ) + FUTURE_TIMESTAMP_TOLERANCE ) ;
40
+ }
41
+
23
42
export async function addPostToTimeline (
24
43
db : Database ,
25
44
post : Post ,
@@ -235,6 +254,7 @@ export async function getPublicTimeline(
235
254
window,
236
255
} : PublicTimelineOptions ,
237
256
) : Promise < TimelineEntry [ ] > {
257
+ const futureTimestampLimit = getFutureTimestampLimit ( ) ;
238
258
const posts = await db . query . postTable . findMany ( {
239
259
with : {
240
260
actor : {
@@ -401,6 +421,7 @@ export async function getPublicTimeline(
401
421
...( withoutShares ? { sharedPostId : { isNull : true } } : undefined ) ,
402
422
...( postType == null ? undefined : { type : postType } ) ,
403
423
...( until == null ? undefined : { published : { lte : until } } ) ,
424
+ published : { lte : futureTimestampLimit } ,
404
425
} ,
405
426
] ,
406
427
} ,
@@ -430,6 +451,7 @@ export async function getPersonalTimeline(
430
451
window,
431
452
} : PersonalTimelineOptions ,
432
453
) : Promise < TimelineEntry [ ] > {
454
+ const futureTimestampLimit = getFutureTimestampLimit ( ) ;
433
455
const timeline = await db . query . timelineItemTable . findMany ( {
434
456
with : {
435
457
post : {
@@ -559,6 +581,11 @@ export async function getPersonalTimeline(
559
581
currentAccount . hideForeignLanguages && currentAccount . locales != null
560
582
? { language : { in : currentAccount . locales } }
561
583
: { } ,
584
+ {
585
+ published : {
586
+ lte : futureTimestampLimit ,
587
+ } ,
588
+ } ,
562
589
] ,
563
590
} ,
564
591
...( withoutShares ? { originalAuthorId : { isNotNull : true } } : { } ) ,
0 commit comments