Skip to content

Commit

Permalink
public-api: remove pagination logic and transfer-encoding header (#1706)
Browse files Browse the repository at this point in the history
fix: remove pagination logic and transfer-encoding header
  • Loading branch information
Mini256 authored Dec 18, 2023
1 parent a407309 commit d6f8ba5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export class TiDBDataService {
const res = await this.client.get(`${originalPath}`);
const endTime = DateTime.now();
const duration = endTime.diff(startTime, 'seconds').seconds;
this.logger.info(`✅ Finished request TiDB Data Service (endpoint: ${endpointName}), cost: ${duration} s.`);
this.logger.info({
targetURL: originalPath,
endpoint: endpointName,
}, `✅ Finished request to TiDB Data Service (endpoint: ${endpointName}), cost: ${duration} s.`);
return res;
});
});
Expand Down
33 changes: 6 additions & 27 deletions packages/api-server/src/utils/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,10 @@ export function proxyGet(
// Map query params to query strings.
const query = req.query as any;
const queryKeys = Object.keys(query);

let limit = 30;
if (queryKeys.find((queryKey) => queryKey === 'page_size')) {
try {
limit = Number(query['page_size']);
} catch (e) {
throw new APIError(400, 'Invalid page_size number.');
}
}

const queryStrings = queryKeys.map((queryKey) => {
// Mapping the page and page_size to offset and limit.
// TODO: remove it after TiDB data service supports page and page_size.
if (queryKey === 'page') {
let offset = 0;
try {
offset = (Math.max(1, Number(query['page'])) - 1) * limit;
} catch (e) {
throw new APIError(400, 'Invalid page number.');
}
return `offset=${offset}`;
} else if (queryKey === 'page_size') {
return `limit=${limit}`;
} else {
return `${queryKey}=${query[queryKey]}`;
}
});
const queryStrings = [];
queryStrings.push(...queryKeys.map((queryKey) => {
return `${queryKey}=${query[queryKey]}`;
}));

// Remove path params from url.
const params = req.params as any;
Expand All @@ -78,6 +55,8 @@ export function proxyGet(
// Retrieve query result from TiDB data service.
const targetURL = `${pathname}?${queryStrings.join('&')}`;
const res = await app.tidbDataService.request(targetURL);
delete res.headers['transfer-encoding'];

reply
.code(res.status)
.headers(res.headers)
Expand Down

0 comments on commit d6f8ba5

Please sign in to comment.