mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-26 05:10:41 +03:00
14 lines
408 B
JavaScript
14 lines
408 B
JavaScript
|
const UserModel = require("./User");
|
||
|
const UserCache = [];
|
||
|
|
||
|
module.exports.getAuthor = async function () {
|
||
|
console.log("User Cache Length:", UserCache.length);
|
||
|
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;
|
||
|
}
|