Skip to content

Commit

Permalink
removes if for data loader. We want the data to update on every build
Browse files Browse the repository at this point in the history
  • Loading branch information
mcancellieri committed Dec 15, 2023
1 parent cbee45a commit df940c5
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class Loader {

async getData() {
let cachedData
const date = new Date()
try {
cachedData = JSON.parse(
fs.readFileSync(path.join(__dirname, this.fileName), 'utf8')
Expand All @@ -49,22 +48,21 @@ class Loader {
this.log('data cache not initialized')
}
// Fetch data once a day
if (!cachedData || date.getDate() !== cachedData.timestamp) {
const data = await this.fetchData(this.baseUrl)
try {
fs.writeFileSync(
path.join(__dirname, this.fileName),
JSON.stringify(data),
'utf8'
)
this.log('Wrote to data cache')
} catch (error) {
this.log('Error writing data to file')
this.log(error)
}

cachedData = data
const data = await this.fetchData(this.baseUrl)
try {
fs.writeFileSync(
path.join(__dirname, this.fileName),
JSON.stringify(data),
'utf8'
)
this.log('Wrote to data cache')
} catch (error) {
this.log('Error writing data to file')
this.log(error)
}

cachedData = data
return cachedData
}
}
Expand Down

0 comments on commit df940c5

Please sign in to comment.