Browse Source

用时测试

dev
巴林闲侠 2 years ago
parent
commit
af1d91a200
  1. 2
      api/.vscode/launch.json
  2. 10
      api/app/lib/controllers/alarm/data.js
  3. 6
      api/app/lib/controllers/alarm/video.js
  4. 2
      api/app/lib/controllers/console/toolLink.js
  5. 2
      api/app/lib/controllers/project/index.js
  6. 6
      api/app/lib/middlewares/authenticator.js

2
api/.vscode/launch.json

@ -51,7 +51,7 @@
// "--clickHouseDataAlarm default", // "--clickHouseDataAlarm default",
// //
"--clickHouseAnxincloud Anxinyun11", "--clickHouseAnxincloud Anxinyun12",
"--clickHousePepEmis pepca8", "--clickHousePepEmis pepca8",
"--clickHouseProjectManage peppm8", "--clickHouseProjectManage peppm8",
"--clickHouseVcmp video_access_dev", "--clickHouseVcmp video_access_dev",

10
api/app/lib/controllers/alarm/data.js

@ -19,7 +19,7 @@ async function groupList (ctx) {
ctx.status = 200; ctx.status = 200;
ctx.body = groupRes ctx.body = groupRes
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {
message: typeof error == 'string' ? error : undefined message: typeof error == 'string' ? error : undefined
@ -215,7 +215,7 @@ async function detail (ctx) {
ctx.status = 200; ctx.status = 200;
ctx.body = detailRes ctx.body = detailRes
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {
message: typeof error == 'string' ? error : undefined message: typeof error == 'string' ? error : undefined
@ -274,7 +274,7 @@ function confirm (opts) {
ctx.status = 204; ctx.status = 204;
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {
message: typeof error == 'string' ? error : undefined message: typeof error == 'string' ? error : undefined
@ -304,7 +304,7 @@ async function detailAggregation (ctx) {
ctx.status = 200; ctx.status = 200;
ctx.body = alarmDetailAggRes ctx.body = alarmDetailAggRes
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {
message: typeof error == 'string' ? error : undefined message: typeof error == 'string' ? error : undefined
@ -324,7 +324,7 @@ async function alarmCount (ctx) {
ctx.status = 200; ctx.status = 200;
ctx.body = alarmUnconfirmedAggRes ctx.body = alarmUnconfirmedAggRes
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {
message: typeof error == 'string' ? error : undefined message: typeof error == 'string' ? error : undefined

6
api/app/lib/controllers/alarm/video.js

@ -6,7 +6,7 @@ async function deviceType (ctx) {
ctx.status = 200; ctx.status = 200;
ctx.body = [] ctx.body = []
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {
message: typeof error == 'string' ? error : undefined message: typeof error == 'string' ? error : undefined
@ -146,7 +146,7 @@ async function alarmList (ctx) {
ctx.status = 200; ctx.status = 200;
ctx.body = returnD ctx.body = returnD
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {
message: typeof error == 'string' ? error : undefined message: typeof error == 'string' ? error : undefined
@ -160,7 +160,7 @@ async function confirm (ctx) {
ctx.status = 20; ctx.status = 20;
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {
message: typeof error == 'string' ? error : undefined message: typeof error == 'string' ? error : undefined

2
api/app/lib/controllers/console/toolLink.js

@ -6,7 +6,7 @@ async function add (ctx) {
ctx.status = 20; ctx.status = 20;
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {
message: typeof error == 'string' ? error : undefined message: typeof error == 'string' ? error : undefined

2
api/app/lib/controllers/project/index.js

@ -96,7 +96,7 @@ async function pomsProject (ctx) {
ctx.status = 200; ctx.status = 200;
ctx.body = proRes ctx.body = proRes
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {
message: typeof error == 'string' ? error : undefined message: typeof error == 'string' ? error : undefined

6
api/app/lib/middlewares/authenticator.js

@ -66,14 +66,16 @@ let isPathExcluded = function (opts, path, method) {
}; };
let authorizeToken = async function (ctx, token) { let authorizeToken = async function (ctx, token) {
let startTime = moment()
let rslt = null; let rslt = null;
const tokenFormatRegexp = /^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$/g; const tokenFormatRegexp = /^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$/g;
if (token && tokenFormatRegexp.test(token)) { if (token && tokenFormatRegexp.test(token)) {
try { try {
console.log(`DurationCalc: auth 1 用时 ${moment().diff(startTime, 'milliseconds')}`);
const authorizeRes = await ctx.app.fs.emisRequest.get('authorize', { const authorizeRes = await ctx.app.fs.emisRequest.get('authorize', {
query: { token } query: { token }
}) })
console.log(`DurationCalc: auth 2 用时 ${moment().diff(startTime, 'milliseconds')}`);
const { userInfo, expired } = authorizeRes; const { userInfo, expired } = authorizeRes;
if (expired && moment().valueOf() <= moment(expired).valueOf()) { if (expired && moment().valueOf() <= moment(expired).valueOf()) {
const pomsUser = await ctx.app.fs.dc.models.User.findOne({ const pomsUser = await ctx.app.fs.dc.models.User.findOne({
@ -81,6 +83,7 @@ let authorizeToken = async function (ctx, token) {
pepUserId: userInfo.id pepUserId: userInfo.id
} }
}) || {} }) || {}
console.log(`DurationCalc: auth 3 用时 ${moment().diff(startTime, 'milliseconds')}`);
rslt = { rslt = {
'authorized': userInfo.authorized, 'authorized': userInfo.authorized,
'resources': (userInfo || {}).resources || [], 'resources': (userInfo || {}).resources || [],
@ -91,6 +94,7 @@ let authorizeToken = async function (ctx, token) {
ctx.fs.api.pepUserInfo = userInfo; ctx.fs.api.pepUserInfo = userInfo;
ctx.fs.api.token = token; ctx.fs.api.token = token;
} }
console.log(`DurationCalc: auth 4 用时 ${moment().diff(startTime, 'milliseconds')}`);
} catch (err) { } catch (err) {
const { error } = err.response || {}; const { error } = err.response || {};
ctx.fs.logger.log('[anxinyun]', '[AUTH] failed', (error || {}).message || `cannot GET /users/${token}`); ctx.fs.logger.log('[anxinyun]', '[AUTH] failed', (error || {}).message || `cannot GET /users/${token}`);

Loading…
Cancel
Save