Add option to get only summary info for a sequence.

Which is faster when we don't need the shotpoint data.
This commit is contained in:
D. Berge
2021-10-03 21:23:39 +02:00
parent ef12168811
commit b107c71c6f

View File

@@ -22,8 +22,27 @@ function thinout (key, obj) {
return value;
}
async function getSummary (projectId, sequence, opts = {}) {
const client = await setSurvey(projectId);
const text = `
SELECT *
FROM sequences_summary
WHERE sequence = $1;
`;
const res = await client.query(text, [sequence]);
client.release();
return res.rows[0];
}
async function get (projectId, sequence, opts = {}) {
if (opts.summary) {
return await getSummary(projectId, sequence, opts);
}
const client = await setSurvey(projectId);
const sortFields = [
@@ -33,11 +52,11 @@ async function get (projectId, sequence, opts = {}) {
const sortDir = opts.sortDesc == "false" ? "ASC" : "DESC";
const offset = Math.abs((opts.page-1)*opts.itemsPerPage) || 0;
const limit = Math.abs(Number(opts.itemsPerPage)) || null;
const restriction = sequence != 0
? "sequence = $3"
: "TRUE OR $3";
const text = `
SELECT
sequence, sailline, line, point, tstamp,
@@ -58,7 +77,7 @@ async function get (projectId, sequence, opts = {}) {
const values = [offset, limit, sequence, opts.path || "$"];
const res = await client.query(text, values);
client.release();
if (opts.project) {
const tokens = opts.project.split(/\s*[,;:\s]\s*/).filter(e => e.length);
const project = tokens.map(i => i.replace(/^([^.]+)\..*$/, "$1"));