mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-03 04:37:40 +01:00
Cache parsed timestamps for quicker rendering
This commit is contained in:
parent
3912c67965
commit
a9ec171c50
@ -602,7 +602,24 @@ export function isOdd(number) {
|
||||
return number % 2 !== 0;
|
||||
}
|
||||
|
||||
const dateCache = new Map();
|
||||
|
||||
/**
|
||||
* Cached version of moment() to avoid re-parsing the same date strings.
|
||||
* @param {any} timestamp String or number representing a date.
|
||||
* @returns {*} Moment object
|
||||
*/
|
||||
export function timestampToMoment(timestamp) {
|
||||
if (dateCache.has(timestamp)) {
|
||||
return dateCache.get(timestamp);
|
||||
}
|
||||
|
||||
const moment = parseTimestamp(timestamp);
|
||||
dateCache.set(timestamp, moment);
|
||||
return moment;
|
||||
}
|
||||
|
||||
function parseTimestamp(timestamp) {
|
||||
if (!timestamp) {
|
||||
return moment.invalid();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user