Added rounding to Comments-UI API fetch timestamp (#19750)

no issue

- allows for comments to be cached for 10s to greatly reduce the load hitting Ghost
This commit is contained in:
Kevin Ansfield 2024-02-23 19:53:27 +00:00 committed by GitHub
parent afe1350008
commit ef38316976
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -122,7 +122,11 @@ function setupGhostApi({siteUrl = window.location.origin, apiUrl, apiKey}: {site
return json;
},
browse({page, postId}: {page: number, postId: string}) {
firstCommentsLoadedAt = firstCommentsLoadedAt ?? new Date().toISOString();
// use the most recent round 10sec timestamp to fetch comments so we can have some caching
const now = Date.now();
const timestamp = (new Date(now - (now % 10000))).toISOString();
firstCommentsLoadedAt = firstCommentsLoadedAt ?? timestamp;
const filter = encodeURIComponent(`post_id:'${postId}'+created_at:<=${firstCommentsLoadedAt}`);
const order = encodeURIComponent('created_at DESC, id DESC');