@steedos/service-pages 3.0.13-beta.35 → 3.0.13-beta.37
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.
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
name: pages_schema
|
|
2
2
|
objectApiName: pages
|
|
3
3
|
isEnabled: true
|
|
4
|
-
script: |-
|
|
4
|
+
script: |-
|
|
5
5
|
const pageId = ctx.input.pageId;
|
|
6
6
|
|
|
7
7
|
if (!pageId) {
|
|
8
8
|
throw new Error("pageId parameter is missing");
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
const _t0 = Date.now();
|
|
12
|
+
|
|
11
13
|
const pages = await ctx.getObject('pages').find({
|
|
12
14
|
filters: [['name', '=', pageId], "or", ['_id', '=', pageId]],
|
|
13
15
|
top: 1
|
|
14
16
|
});
|
|
17
|
+
console.log(`[PerfLog] [pages_schema.function] pages.find done | pageId=${pageId} | cost=${Date.now()-_t0}ms | rows=${pages ? pages.length : 0}`);
|
|
15
18
|
|
|
16
19
|
// Fix: Check if a version was actually found to avoid "undefined" errors
|
|
17
20
|
if (!pages || pages.length === 0) {
|
|
@@ -20,11 +23,13 @@ script: |-
|
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
const filters = [['page', '=', pages[0]._id], ['is_active', '=', true]];
|
|
26
|
+
const _t1 = Date.now();
|
|
23
27
|
const pageVersions = await ctx.getObject('page_versions').find({
|
|
24
28
|
filters: filters,
|
|
25
29
|
sort: 'version desc',
|
|
26
30
|
top: 1
|
|
27
31
|
});
|
|
32
|
+
console.log(`[PerfLog] [pages_schema.function] page_versions.find done | pageId=${pageId} | cost=${Date.now()-_t1}ms | rows=${pageVersions ? pageVersions.length : 0}`);
|
|
28
33
|
|
|
29
34
|
// Fix: Check if a version was actually found to avoid "undefined" errors
|
|
30
35
|
if (!pageVersions || pageVersions.length === 0) {
|
|
@@ -43,6 +48,8 @@ script: |-
|
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
|
|
51
|
+
console.log(`[PerfLog] [pages_schema.function] total done | pageId=${pageId} | cost=${Date.now()-_t0}ms`);
|
|
52
|
+
|
|
46
53
|
return {
|
|
47
54
|
"type": "inject",
|
|
48
55
|
"assets": [
|
|
@@ -54,5 +61,4 @@ script: |-
|
|
|
54
61
|
}
|
|
55
62
|
],
|
|
56
63
|
"body": [schema]
|
|
57
|
-
};
|
|
58
|
-
locked: false
|
|
64
|
+
};
|
|
@@ -18,6 +18,7 @@ router.get('/api/pageSchema/:type', auth.requireAuthentication, async function (
|
|
|
18
18
|
const { app, objectApiName, recordId, pageId, formFactor} = req.query;
|
|
19
19
|
const { type } = req.params;
|
|
20
20
|
|
|
21
|
+
const _t0 = Date.now();
|
|
21
22
|
const pageSchema = await objectql.getSteedosSchema().broker.call(`page.getMeSchema`, {
|
|
22
23
|
type,
|
|
23
24
|
app,
|
|
@@ -30,6 +31,7 @@ router.get('/api/pageSchema/:type', auth.requireAuthentication, async function (
|
|
|
30
31
|
user: userSession
|
|
31
32
|
}
|
|
32
33
|
});
|
|
34
|
+
process.stdout.write(`[PerfLog] [page_schema.router] broker.call page.getMeSchema done | type=${type} | pageId=${pageId} | objectApiName=${objectApiName} | cost=${Date.now()-_t0}ms | hasSchema=${!!(pageSchema && pageSchema.schema)}\n`);
|
|
33
35
|
|
|
34
36
|
res.send(pageSchema || {});
|
|
35
37
|
} catch (error) {
|
|
@@ -29,7 +29,11 @@ module.exports = {
|
|
|
29
29
|
async handler(ctx) {
|
|
30
30
|
const userSession = ctx.meta.user;
|
|
31
31
|
const { type, app, objectApiName, recordId, pageId, formFactor } = ctx.params;
|
|
32
|
-
|
|
32
|
+
const _t0 = Date.now();
|
|
33
|
+
process.stdout.write(`[PerfLog] [page.getMeSchema action] start | pageId=${pageId} | type=${type} | objectApiName=${objectApiName}\n`);
|
|
34
|
+
const _result = await this.getMeSchema(type, app, objectApiName, recordId, pageId, formFactor, userSession);
|
|
35
|
+
process.stdout.write(`[PerfLog] [page.getMeSchema action] done | pageId=${pageId} | type=${type} | objectApiName=${objectApiName} | cost=${Date.now()-_t0}ms | hasSchema=${!!(_result && _result.schema)}\n`);
|
|
36
|
+
return _result;
|
|
33
37
|
}
|
|
34
38
|
},
|
|
35
39
|
//发布最新版
|
|
@@ -256,11 +260,14 @@ module.exports = {
|
|
|
256
260
|
async handler(type, app, objectApiName, recordId, formFactor, userSession) {
|
|
257
261
|
const pageRender = this.settings.pageRender;
|
|
258
262
|
if (pageRender) {
|
|
259
|
-
|
|
263
|
+
const _t0 = Date.now();
|
|
264
|
+
const _result = await this.broker.call(`${pageRender}.getDefaultSchema`, {type, app, objectApiName, recordId, formFactor}, {
|
|
260
265
|
meta: {
|
|
261
266
|
user: userSession
|
|
262
267
|
}
|
|
263
|
-
})
|
|
268
|
+
});
|
|
269
|
+
process.stdout.write(`[PerfLog] [getDefaultSchema] broker.call ${pageRender}.getDefaultSchema done | type=${type} | objectApiName=${objectApiName} | cost=${Date.now()-_t0}ms | hasResult=${!!_result}\n`);
|
|
270
|
+
return _result;
|
|
264
271
|
}
|
|
265
272
|
return;
|
|
266
273
|
}
|
|
@@ -365,42 +372,60 @@ module.exports = {
|
|
|
365
372
|
},
|
|
366
373
|
getMeSchema: {
|
|
367
374
|
async handler(type, app, objectApiName, recordId, pageId, formFactor, userSession) {
|
|
375
|
+
const _t0 = Date.now();
|
|
368
376
|
if(pageId){
|
|
377
|
+
const _t1 = Date.now();
|
|
369
378
|
const records = await objectql.getObject('pages').find({filters: [['name', '=', pageId]]});
|
|
379
|
+
process.stdout.write(`[PerfLog] [getMeSchema] pages.find done | pageId=${pageId} | cost=${Date.now()-_t1}ms | rows=${records.length}\n`);
|
|
370
380
|
let pageInfo = {};
|
|
371
381
|
if(records.length > 0){
|
|
372
382
|
pageInfo = records[0];
|
|
383
|
+
const _t2 = Date.now();
|
|
373
384
|
const pageVersion = await this.getLatestPageVersion(pageInfo._id, true);
|
|
385
|
+
process.stdout.write(`[PerfLog] [getMeSchema] getLatestPageVersion done | pageId=${pageId} | pageInfoId=${pageInfo._id} | cost=${Date.now()-_t2}ms | hasSchema=${!!(pageVersion && pageVersion.schema)}\n`);
|
|
374
386
|
if(pageVersion && pageVersion.schema){
|
|
387
|
+
process.stdout.write(`[PerfLog] [getMeSchema] total done | pageId=${pageId} | cost=${Date.now()-_t0}ms | result=pageVersion schema\n`);
|
|
375
388
|
return Object.assign({}, pageInfo, {schema: pageVersion.schema});
|
|
376
389
|
}
|
|
377
390
|
}
|
|
391
|
+
process.stdout.write(`[PerfLog] [getMeSchema] total done | pageId=${pageId} | cost=${Date.now()-_t0}ms | result=null\n`);
|
|
378
392
|
return ;
|
|
379
393
|
|
|
380
394
|
}
|
|
381
395
|
// 计算 userSchema
|
|
396
|
+
const _t3 = Date.now();
|
|
382
397
|
const userPage = await this.getUserPage(type, app, objectApiName, recordId, formFactor, userSession);
|
|
398
|
+
process.stdout.write(`[PerfLog] [getMeSchema] getUserPage done | type=${type} | objectApiName=${objectApiName} | cost=${Date.now()-_t3}ms | hasPage=${!!userPage}\n`);
|
|
383
399
|
if (userPage) {
|
|
400
|
+
const _t4 = Date.now();
|
|
384
401
|
const pageVersion = await this.getLatestPageVersion(userPage._id, true);
|
|
402
|
+
process.stdout.write(`[PerfLog] [getMeSchema] getLatestPageVersion (userPage) done | pageId=${userPage._id} | cost=${Date.now()-_t4}ms | hasSchema=${!!(pageVersion && pageVersion.schema)}\n`);
|
|
385
403
|
if(pageVersion && pageVersion.schema){
|
|
404
|
+
process.stdout.write(`[PerfLog] [getMeSchema] total done | type=${type} | objectApiName=${objectApiName} | cost=${Date.now()-_t0}ms | result=userPage schema\n`);
|
|
386
405
|
return Object.assign({}, userPage, {schema: pageVersion.schema});
|
|
387
406
|
}
|
|
388
407
|
}
|
|
408
|
+
const _t5 = Date.now();
|
|
389
409
|
const defaultSchema = await this.getDefaultSchema(type, app, objectApiName, recordId, formFactor, userSession);
|
|
410
|
+
process.stdout.write(`[PerfLog] [getMeSchema] getDefaultSchema done | type=${type} | objectApiName=${objectApiName} | cost=${Date.now()-_t5}ms | hasSchema=${!!defaultSchema}\n`);
|
|
390
411
|
if(defaultSchema){
|
|
391
412
|
const pageRender = this.settings.pageRender;
|
|
413
|
+
process.stdout.write(`[PerfLog] [getMeSchema] total done | type=${type} | objectApiName=${objectApiName} | cost=${Date.now()-_t0}ms | result=defaultSchema\n`);
|
|
392
414
|
return { render_engine: pageRender , schema: defaultSchema}
|
|
393
415
|
}
|
|
416
|
+
process.stdout.write(`[PerfLog] [getMeSchema] total done | type=${type} | objectApiName=${objectApiName} | cost=${Date.now()-_t0}ms | result=null\n`);
|
|
394
417
|
}
|
|
395
418
|
},
|
|
396
419
|
getLatestPageVersion:{
|
|
397
420
|
async handler(pageId, isArchived) {
|
|
421
|
+
const _t0 = Date.now();
|
|
398
422
|
const filters = [['page', '=', pageId]];
|
|
399
423
|
if(isArchived){
|
|
400
424
|
filters.push(['is_active','=',true])
|
|
401
425
|
}
|
|
402
426
|
// 根据pageId 获取 page version
|
|
403
427
|
const pageVersions = await objectql.getObject('page_versions').find({filters: filters, sort: 'version desc', top: 1});
|
|
428
|
+
process.stdout.write(`[PerfLog] [getLatestPageVersion] page_versions.find done | pageId=${pageId} | isArchived=${isArchived} | cost=${Date.now()-_t0}ms | rows=${pageVersions.length}\n`);
|
|
404
429
|
if(pageVersions.length === 1){
|
|
405
430
|
return pageVersions[0]
|
|
406
431
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/service-pages",
|
|
3
|
-
"version": "3.0.13-beta.
|
|
3
|
+
"version": "3.0.13-beta.37",
|
|
4
4
|
"main": "package.service.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
|
-
"gitHead": "
|
|
9
|
+
"gitHead": "9295f880f15ee69bfdee1549fcbba116f384128f",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"clone": "^2.1.2",
|
|
12
12
|
"ejs": "^3.1.8"
|