@@ -17,17 +17,19 @@ export default async function getCommentsCached(postName: string) {
17
17
const data = await loadAndRender ( postName )
18
18
COMMENTS_CACHE . set ( postName , { data, timestamp : Date . now ( ) } )
19
19
return data
20
- } else if ( ! POST_COMMENTS_LOADING . get ( postName ) && ( Date . now ( ) - cached . timestamp > COMMENTS_CACHE_LIFETIME ) ) {
21
- // if comments are cached but expired, start updating them but return cached for now
22
- POST_COMMENTS_LOADING . set ( postName , true )
23
- loadAndRender ( postName )
24
- . then ( data =>
25
- COMMENTS_CACHE . set ( postName , { data, timestamp : Date . now ( ) } ) )
26
- . finally ( ( ) => POST_COMMENTS_LOADING . set ( postName , false ) )
27
-
28
- return cached . data
29
20
} else {
30
- // if cached and not expired, just return
21
+ if ( ! POST_COMMENTS_LOADING . get ( postName ) && ( Date . now ( ) - cached . timestamp > COMMENTS_CACHE_LIFETIME ) ) {
22
+ try {
23
+ // if comments are cached but expired, start updating them but return cached for now
24
+ POST_COMMENTS_LOADING . set ( postName , true )
25
+ loadAndRender ( postName )
26
+ . then ( data =>
27
+ COMMENTS_CACHE . set ( postName , { data, timestamp : Date . now ( ) } ) )
28
+ . finally ( ( ) => POST_COMMENTS_LOADING . set ( postName , false ) )
29
+ } catch {
30
+ }
31
+ }
32
+
31
33
return cached . data
32
34
}
33
35
}
@@ -94,7 +96,7 @@ function renderComments({ id, by, text, time, kids }: Comment): string {
94
96
html `< div class ="children ">
95
97
${ kids . map ( renderComments ) . join ( '' ) }
96
98
</ div > `
97
- : '' }
99
+ : '' }
98
100
`
99
101
}
100
102
0 commit comments