0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Stripped moment from BaseSiteMapGenerator

- moment calls are unbelievably heavy and we should do away with it
  where possible
- this code doesn't need moment and we can just use native JS Date here
- this saves about 5% CPU time when booting sites with a lot of posts
This commit is contained in:
Daniel Lockyer 2024-10-14 11:50:32 +02:00 committed by Daniel Lockyer
parent b376585c64
commit 30220aa6ef

View file

@ -1,6 +1,5 @@
const _ = require('lodash');
const xml = require('xml');
const moment = require('moment');
const path = require('path');
const urlUtils = require('../../../shared/url-utils');
const localUtils = require('./utils');
@ -96,23 +95,24 @@ class BaseSiteMapGenerator {
}
/**
* @returns {moment.Moment}
* @returns {Date}
*/
getLastModifiedForDatum(datum) {
if (datum.updated_at || datum.published_at || datum.created_at) {
const modifiedDate = datum.updated_at || datum.published_at || datum.created_at;
return moment(modifiedDate);
return new Date(modifiedDate);
} else {
return moment();
return new Date();
}
}
updateLastModified(datum) {
const lastModified = this.getLastModifiedForDatum(datum);
const lastModifiedTime = lastModified.getTime();
if (lastModified > this.lastModified) {
this.lastModified = lastModified;
if (lastModifiedTime > this.lastModified) {
this.lastModified = lastModifiedTime;
}
}