cache series i think

master
Kit Kasune 2 years ago
parent 6fe11be108
commit 4a91a96e5a
  1. 7
      api/util/startup/cache.js
  2. 27
      api/util/startup/cache/series.js

@ -4,7 +4,9 @@ const chalk = require('chalk');
module.exports = async app => { module.exports = async app => {
app.cache = { app.cache = {
users: {} users: {},
series: {},
seriesCount: 0
}; };
return new Promise(async resolve => { return new Promise(async resolve => {
@ -14,6 +16,9 @@ module.exports = async app => {
let userCache = spin.add("ar", {text: "Caching Users..."}); let userCache = spin.add("ar", {text: "Caching Users..."});
loaders.push(require('./cache/users')(app, userCache)); loaders.push(require('./cache/users')(app, userCache));
let seriesCache = spin.add("ar", {text: "Caching Series..."});
loaders.push(require('./cache/series')(app, seriesCache));
await Promise.all(loaders); await Promise.all(loaders);
console.log(''); console.log('');
resolve(0); resolve(0);

@ -0,0 +1,27 @@
const chalk = require('chalk');
module.exports = async (app, spinner) => {
const Series = app.db.models.ani.series;
return new Promise(async resolve => {
const st = new Date().getTime();
let amount = 1;
for await (const series of Series.find()) {
let {id, name, romaji, kanji, altNames, genres, tags} = series;
app.cache.series[series.id] = {id, name, romaji, kanji, altNames, genres, tags}; //keep an in-memory index of series' searchable items
app.cache.series[series.id].synopsis = series.synopsis.synopsis;
console.log(app.cache.series[series.id]);
spinner.update({text: `${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${amount}`)} ${chalk.blueBright(`ani DB series.`)}`});
app.cache.seriesCount++;
amount++;
}
const cacheTime = new Date().getTime() - st;
spinner.update({text: `${spinner.options.text.slice(0, 19).trim()} ${chalk.gray(`${cacheTime}ms >>`.padStart(8, '0').padStart(7, '0'))} ${spinner.options.text.slice(19).trim()}`});
spinner.status('non-spinnable');
resolve(0);
});
}
Loading…
Cancel
Save