open-art.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * 每天运行一次,每次放开100条记录
  3. */
  4. const models = require('../../models');
  5. const { tags, refreshTagCount } = require('../../config/tag');
  6. const openCount = 100; // 每天开放的内容量
  7. async function run() {
  8. let done = 0;
  9. let duration = 0;
  10. let hour, minute, second;
  11. let start = Date.now();
  12. let docs = await models.Art.find({ open: false }).sort({ lastMod: 1 }).limit(openCount);
  13. let total = docs.length;
  14. console.log('total:', total);
  15. for (let doc of docs) {
  16. doc.open = true;
  17. await doc.save();
  18. done++;
  19. duration = (Date.now() - start) / 1000;
  20. hour = (Math.floor(duration / 60 / 60)).toString().padStart(2, '0');
  21. minute = (Math.floor(duration / 60) % 60).toString().padStart(2, '0');
  22. second = (Math.floor(duration) % 60).toString().padStart(2, '0');
  23. console.log('progress: ' + Math.floor((100 * done / total)) + '% used time: ' + hour + ':' + minute + ':' + second);
  24. }
  25. // video story 的内容全部开放
  26. docs = await models.Art.find({ open: false, tags: 'video-story' });
  27. for (let doc of docs) {
  28. console.log(`open video-story art: ${doc._id}`);
  29. doc.open = true;
  30. await doc.save();
  31. }
  32. // 更新tag信息
  33. await refreshTagCount();
  34. }
  35. module.exports = { run }
  36. if (require.main == module) {
  37. run();
  38. }