Browse Source

chore: add response time header

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5132/head
Pranav C 2 years ago
parent
commit
6b827c0bf7
  1. 13
      packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts
  2. 4
      packages/nocodb/src/lib/meta/api/helpers/apiHelpers.ts
  3. 1
      packages/nocodb/src/lib/meta/api/helpers/index.ts

13
packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts

@ -10,11 +10,16 @@ import ncMetaAclMw from '../../helpers/ncMetaAclMw';
import { getViewAndModelFromRequestByAliasOrId } from './helpers'; import { getViewAndModelFromRequestByAliasOrId } from './helpers';
import apiMetrics from '../../helpers/apiMetrics'; import apiMetrics from '../../helpers/apiMetrics';
import getAst from '../../../db/sql-data-mapper/lib/sql/helpers/getAst'; import getAst from '../../../db/sql-data-mapper/lib/sql/helpers/getAst';
import { parseHrtimeToSeconds } from '../helpers';
// todo: Handle the error case where view doesnt belong to model // todo: Handle the error case where view doesnt belong to model
async function dataList(req: Request, res: Response) { async function dataList(req: Request, res: Response) {
const startTime = process.hrtime();
const { model, view } = await getViewAndModelFromRequestByAliasOrId(req); const { model, view } = await getViewAndModelFromRequestByAliasOrId(req);
res.json(await getDataList(model, view, req)); const responseData = await getDataList(model, view, req);
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(startTime));
res.setHeader('xc-db-response', elapsedSeconds);
res.json(responseData);
} }
async function dataFindOne(req: Request, res: Response) { async function dataFindOne(req: Request, res: Response) {
@ -226,8 +231,12 @@ async function dataExist(req: Request, res: Response) {
// todo: Handle the error case where view doesnt belong to model // todo: Handle the error case where view doesnt belong to model
async function groupedDataList(req: Request, res: Response) { async function groupedDataList(req: Request, res: Response) {
const startTime = process.hrtime();
const { model, view } = await getViewAndModelFromRequestByAliasOrId(req); const { model, view } = await getViewAndModelFromRequestByAliasOrId(req);
res.json(await getGroupedDataList(model, view, req)); const groupedData = await getGroupedDataList(model, view, req);
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(startTime));
res.setHeader('xc-db-response', elapsedSeconds);
res.json(groupedData);
} }
async function getGroupedDataList(model, view: View, req) { async function getGroupedDataList(model, view: View, req) {

4
packages/nocodb/src/lib/meta/api/helpers/apiHelpers.ts

@ -0,0 +1,4 @@
export function parseHrtimeToSeconds(hrtime) {
const seconds = (hrtime[0] + hrtime[1] / 1e6).toFixed(3);
return seconds;
}

1
packages/nocodb/src/lib/meta/api/helpers/index.ts

@ -1,4 +1,5 @@
import { populateMeta } from './populateMeta'; import { populateMeta } from './populateMeta';
export * from './columnHelpers'; export * from './columnHelpers';
export * from './apiHelpers';
export { populateMeta }; export { populateMeta };

Loading…
Cancel
Save