Skip to content

Commit

Permalink
Limit the amount of data from search
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgalore committed Jun 19, 2024
1 parent 4380bc8 commit 5fd2978
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion server/src/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import DatabaseHelper from './databasehelper.js';

const logger = log.getLogger('sitespeedio.database');

const LIMITED_COLUMS =
'id, location, test_type, run_date, browser_name, url, result_url, status, scripting_name, label, slug';

function logError(message, error) {
if (error instanceof AggregateError) {
for (const [index, theError] of error.errors.entries()) {
Expand Down Expand Up @@ -73,7 +76,9 @@ export async function updateStatus(id, status) {
*/
export async function getLatestTests(limit, page) {
const select =
'SELECT * FROM sitespeed_io_test_runs ORDER BY added_date DESC LIMIT $1 OFFSET $2';
'SELECT ' +
LIMITED_COLUMS +
' FROM sitespeed_io_test_runs ORDER BY added_date DESC LIMIT $1 OFFSET $2';
const count = 'SELECT count(*) FROM sitespeed_io_test_runs';
const offset = (page - 1) * limit;
const values = [limit, offset];
Expand Down
7 changes: 6 additions & 1 deletion server/src/database/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import DatabaseHelper from './databasehelper.js';

const logger = log.getLogger('sitespeedio.database.search');

const LIMITED_COLUMS =
'id, location, test_type, run_date, browser_name, url, result_url, status, scripting_name, label, slug';

/**
* Get a test by text (searching).
*/
Expand All @@ -23,7 +26,9 @@ export async function getTestByText(text, limit, page) {
}

const select =
'SELECT * FROM sitespeed_io_test_runs where ' +
'SELECT ' +
LIMITED_COLUMS +
' FROM sitespeed_io_test_runs where ' +
where.join(' AND ') +
' ORDER BY added_date DESC LIMIT $' +
(parameters.length + 1) +
Expand Down

0 comments on commit 5fd2978

Please sign in to comment.