2023-04-14 06:47:58 -04:00
|
|
|
import TClient from '../client.js';
|
2023-02-26 18:45:56 -05:00
|
|
|
import mongoose from 'mongoose';
|
2023-10-02 18:40:03 -04:00
|
|
|
import CacheServer from '../funcs/CacheServer.js';
|
2023-02-26 18:45:56 -05:00
|
|
|
|
|
|
|
const Schema = mongoose.model('mpserver', new mongoose.Schema({
|
|
|
|
_id: {type: String, required:true},
|
2023-08-15 06:47:31 -04:00
|
|
|
mainServer: {required:true, type: new mongoose.Schema({
|
|
|
|
ip: {type: String, required:true},
|
|
|
|
code: {type: String, required:true}
|
|
|
|
}, {versionKey: false})},
|
|
|
|
secondServer: {required:true, type: new mongoose.Schema({
|
|
|
|
ip: {type: String, required:true},
|
|
|
|
code: {type: String, required:true}
|
|
|
|
}, {versionKey: false})},
|
2023-02-26 18:45:56 -05:00
|
|
|
}, {versionKey: false}));
|
|
|
|
|
|
|
|
export default class MPServer extends Schema {
|
|
|
|
client: TClient;
|
|
|
|
_content: typeof Schema;
|
|
|
|
constructor(client:TClient){
|
|
|
|
super();
|
|
|
|
this.client = client;
|
|
|
|
this._content = Schema;
|
|
|
|
}
|
2023-10-02 18:40:03 -04:00
|
|
|
async findInCache(query:any): Promise<any> {
|
|
|
|
const cacheKey = `MPServer:${query}`;
|
|
|
|
const cachedResult = await CacheServer.get(cacheKey);
|
|
|
|
let result;
|
|
|
|
if (cachedResult) {
|
|
|
|
try {
|
|
|
|
result = cachedResult;
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Error parsing cached result:', error);
|
|
|
|
result = await this._content.findById(query);
|
|
|
|
CacheServer.set(cacheKey, result);
|
|
|
|
CacheServer.expiry(cacheKey, 1800);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = await this._content.findById(query);
|
|
|
|
CacheServer.set(cacheKey, result);
|
|
|
|
CacheServer.expiry(cacheKey, 1800);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2022-11-16 13:53:42 -05:00
|
|
|
}
|