@@ -3,6 +3,9 @@ import path from "path";
3
3
4
4
import type { GetJobsParams } from "./shared.types" ;
5
5
6
+ let _jsearch : any ;
7
+ let _countries : any ;
8
+
6
9
export async function getJobs ( params : GetJobsParams ) {
7
10
try {
8
11
const {
@@ -19,12 +22,16 @@ export async function getJobs(params: GetJobsParams) {
19
22
// Calculate the number of jobs to skip based on the page number and page size
20
23
const skipAmount = ( page - 1 ) * pageSize ;
21
24
22
- const file = path . join ( process . cwd ( ) , "content" , "jsearch.json" ) ;
23
- const fileSync = readFileSync ( file , "utf8" ) ;
25
+ if ( ! _jsearch ) {
26
+ const file = path . join ( process . cwd ( ) , "content" , "jsearch.json" ) ;
27
+ const fileSync = readFileSync ( file , "utf8" ) ;
28
+
29
+ const jsonData = JSON . parse ( fileSync ) ;
24
30
25
- const jsonData = JSON . parse ( fileSync ) ;
31
+ _jsearch = jsonData ;
32
+ }
26
33
27
- const allJobs = jsonData . data || [ ] ;
34
+ const allJobs = _jsearch . data || [ ] ;
28
35
29
36
const searchQueryRegExp = new RegExp (
30
37
( searchQuery || "" ) . toLowerCase ( ) ,
@@ -87,12 +94,16 @@ export async function getJobs(params: GetJobsParams) {
87
94
88
95
export async function getCountryFilters ( ) {
89
96
try {
90
- const file = path . join ( process . cwd ( ) , "content" , "countries.json" ) ;
91
- const fileSync = readFileSync ( file , "utf8" ) ;
97
+ if ( ! _countries ) {
98
+ const file = path . join ( process . cwd ( ) , "content" , "countries.json" ) ;
99
+ const fileSync = readFileSync ( file , "utf8" ) ;
92
100
93
- const jsonData = JSON . parse ( fileSync ) ;
101
+ const jsonData = JSON . parse ( fileSync ) ;
102
+
103
+ _countries = jsonData ;
104
+ }
94
105
95
- const result = jsonData . map ( ( country : any ) => ( {
106
+ const result = _countries . map ( ( country : any ) => ( {
96
107
name : country . name ,
97
108
value : country . cca2 ,
98
109
} ) ) ;
0 commit comments