cgserver 7.0.567 → 7.1.648
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/Config/FrameworkConfig.js +0 -1
- package/dist/lib/Service/MongoCacheService.js +17 -2
- package/dist/lib/WebServer/Decorator/SyncCall.js +21 -0
- package/dist/lib/WebServer/Decorator/SyncCallServer.js +41 -0
- package/dist/lib/WebServer/Engine/Engine.js +6 -0
- package/dist/types/Config/FrameworkConfig.d.ts +0 -1
- package/dist/types/Service/MongoCacheService.d.ts +1 -0
- package/dist/types/WebServer/Decorator/SyncCall.d.ts +7 -0
- package/dist/types/WebServer/Decorator/SyncCallServer.d.ts +7 -0
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GMongoCacheSer = exports.MongoCacheModel = void 0;
|
|
4
|
+
const cgserver_1 = require("../cgserver");
|
|
4
5
|
const MongoBaseService_1 = require("../Database/MongoBaseService");
|
|
5
6
|
const MongoManager_1 = require("../Database/MongoManager");
|
|
6
7
|
//暂时就用这个了,反正没啥用户
|
|
@@ -14,14 +15,28 @@ exports.GMongoCacheSer = null;
|
|
|
14
15
|
class MongoCacheService extends MongoBaseService_1.MongoBaseService {
|
|
15
16
|
constructor() {
|
|
16
17
|
super("cache", MongoCacheModel);
|
|
17
|
-
|
|
18
|
+
cgserver_1.GCgServer.addListener("start", () => {
|
|
19
|
+
this.createIndex({ key: 1 });
|
|
20
|
+
this.createIndex({ "expireAt": 1 }, { expireAfterSeconds: 0 });
|
|
21
|
+
});
|
|
18
22
|
}
|
|
19
23
|
async getData(key) {
|
|
20
|
-
let cm = await
|
|
24
|
+
let cm = await this.get(null, { key: key });
|
|
21
25
|
if (!cm) {
|
|
22
26
|
return null;
|
|
23
27
|
}
|
|
24
28
|
return cm.data;
|
|
25
29
|
}
|
|
30
|
+
async addData(key, data, expireAt = Date.now() + 365 * 24 * 60 * 60 * 1000) {
|
|
31
|
+
let mcm = new MongoCacheModel();
|
|
32
|
+
mcm.key = key;
|
|
33
|
+
mcm.data = data;
|
|
34
|
+
mcm.expireAt = expireAt;
|
|
35
|
+
let rs = await this.updateOne(mcm, { key: mcm.key }, true);
|
|
36
|
+
if (rs.rs.upsertedCount <= 0) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return mcm;
|
|
40
|
+
}
|
|
26
41
|
}
|
|
27
42
|
exports.GMongoCacheSer = new MongoCacheService();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SyncCall = void 0;
|
|
4
|
+
const SyncQueueTool_1 = require("../../Logic/SyncQueueTool");
|
|
5
|
+
/**
|
|
6
|
+
* 异步函数变为同步函数,当前进程有效
|
|
7
|
+
* @param target
|
|
8
|
+
* @param propertyName
|
|
9
|
+
* @param descriptor
|
|
10
|
+
*/
|
|
11
|
+
function SyncCall(target, propertyName, descriptor) {
|
|
12
|
+
let method = descriptor.value;
|
|
13
|
+
descriptor.value = function () {
|
|
14
|
+
let self = this;
|
|
15
|
+
let ret = SyncQueueTool_1.GSyncQueueTool.add(method.name, async () => {
|
|
16
|
+
return await method.apply(self, arguments);
|
|
17
|
+
});
|
|
18
|
+
return ret;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
exports.SyncCall = SyncCall;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SyncCallServer = void 0;
|
|
4
|
+
const Core_1 = require("../../Core/Core");
|
|
5
|
+
const SyncQueueTool_1 = require("../../Logic/SyncQueueTool");
|
|
6
|
+
const MongoCacheService_1 = require("../../Service/MongoCacheService");
|
|
7
|
+
/**
|
|
8
|
+
* 异步函数变为同步函数
|
|
9
|
+
* 服务器间的异步,效率低
|
|
10
|
+
* 只支持mongo模式
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
let SyncCallServer = function () {
|
|
14
|
+
return function (target, propertyName, descriptor) {
|
|
15
|
+
let method = descriptor.value;
|
|
16
|
+
descriptor.value = async () => {
|
|
17
|
+
let key = "sync_" + method.name;
|
|
18
|
+
let func = async () => {
|
|
19
|
+
let item = await MongoCacheService_1.GMongoCacheSer.getData(key);
|
|
20
|
+
let ret = null;
|
|
21
|
+
while (item) {
|
|
22
|
+
await Core_1.core.sleep(200);
|
|
23
|
+
item = await MongoCacheService_1.GMongoCacheSer.getData(key);
|
|
24
|
+
}
|
|
25
|
+
//10秒后过期,避免卡死
|
|
26
|
+
let mcm = await MongoCacheService_1.GMongoCacheSer.addData(key, true, Date.now() + 10 * 1000);
|
|
27
|
+
if (!mcm) {
|
|
28
|
+
await func();
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
};
|
|
32
|
+
await func();
|
|
33
|
+
let ret = SyncQueueTool_1.GSyncQueueTool.add(method.name, async () => {
|
|
34
|
+
return await method.apply(self, arguments);
|
|
35
|
+
});
|
|
36
|
+
await MongoCacheService_1.GMongoCacheSer.deleteOne({ key });
|
|
37
|
+
return ret;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
exports.SyncCallServer = SyncCallServer;
|
|
@@ -78,6 +78,12 @@ class Engine {
|
|
|
78
78
|
let req = new Request_1.Request(_req, this._cfg);
|
|
79
79
|
let res = new Response_1.Response(_res, this._cfg);
|
|
80
80
|
if (req.fileUrl) {
|
|
81
|
+
let fileUrl = req.fileUrl;
|
|
82
|
+
fileUrl = fileUrl.toLocaleLowerCase();
|
|
83
|
+
if (fileUrl.startsWith("data") || fileUrl.startsWith("/data")) {
|
|
84
|
+
res.render404();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
81
87
|
res.renderFile(this._root_path + req.fileUrl);
|
|
82
88
|
return;
|
|
83
89
|
}
|
|
@@ -9,5 +9,6 @@ export declare let GMongoCacheSer: MongoCacheService;
|
|
|
9
9
|
declare class MongoCacheService extends MongoBaseService<MongoCacheModel> {
|
|
10
10
|
constructor();
|
|
11
11
|
getData(key: string): Promise<any>;
|
|
12
|
+
addData(key: string, data: any, expireAt?: number): Promise<MongoCacheModel>;
|
|
12
13
|
}
|
|
13
14
|
export {};
|