akf-forum/models/cache.js
2022-08-31 15:21:04 +03:00

13 lines
No EOL
351 B
JavaScript

const UserModel = require("./User");
const UserCache = [];
module.exports.getAuthor = async function () {
const id = this.authorID || this.author?.id;
let user = UserCache.find(user => user?.id == id)
if (!user) {
user = await UserModel.findOne({ id })
UserCache.push(user)
}
this.author = user;
return this;
}