1
- import { MemoryCache } from '@/MemoryCache' ;
1
+ import { MemoryCache } from '@/lib/cache/ MemoryCache' ;
2
2
import axios from 'axios' ;
3
3
4
4
export function getResolver ( storyIds , stories , cache : MemoryCache ) : any {
@@ -11,22 +11,23 @@ export function getResolver(storyIds, stories, cache: MemoryCache): any {
11
11
const ids : number [ ] = [ ] ;
12
12
const cacheKey = `jobstoryids:${ first } -${ skipText ? 'skipText' : 'dontSkipText' } ` ;
13
13
14
- if ( ! cache . has ( cacheKey ) ) {
14
+ const hasKey = await cache . has ( cacheKey ) ;
15
+ if ( ! hasKey ) {
15
16
const resp = await axios . get ( `${ process . env . HACKERNEWS_API_URL } /jobstories.json?limitToFirst=${ first + 5 } &orderBy="$key"` ) ;
16
17
const data : number [ ] = resp . data ;
17
18
18
19
cache . put ( cacheKey , data , 600 ) ;
19
20
ids . push ( ...data ) ;
20
21
}
21
22
22
- const cacheData = cache . get ( cacheKey ) ;
23
+ const cacheData = await cache . get ( cacheKey ) ;
23
24
24
25
ids . push ( ...cacheData ) ;
25
26
ids . splice ( first ) ;
26
27
27
28
const storyDataPromises = ids
28
- . map ( id => {
29
- if ( cache . has ( `${ kind } story:${ id } ` ) ) {
29
+ . map ( async id => {
30
+ if ( await cache . has ( `${ kind } story:${ id } ` ) ) {
30
31
return null ;
31
32
}
32
33
@@ -42,7 +43,7 @@ export function getResolver(storyIds, stories, cache: MemoryCache): any {
42
43
} ) ;
43
44
44
45
for ( const id of ids ) {
45
- const storyItem = cache . get ( `${ kind } story:${ id } ` ) ;
46
+ const storyItem = await cache . get ( `${ kind } story:${ id } ` ) ;
46
47
47
48
if ( ! storyItem . text || ! skipText ) {
48
49
stories . push ( storyItem ) ;
0 commit comments