mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-14 16:05:05 +03:00
18 lines
No EOL
458 B
JavaScript
18 lines
No EOL
458 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)
|
|
UserCache.push(user = await UserModel.findOne({ id }))
|
|
|
|
if (!this.get('authorID', null, { getters: false })) {
|
|
this.authorID = user.id;
|
|
await this.save();
|
|
}
|
|
|
|
this.author = user;
|
|
|
|
return this;
|
|
} |