mirror of
https://github.com/DeNNiiInc/Web-Page-Performance-Test.git
synced 2026-04-17 20:05:58 +00:00
Fix: History query logic to prioritize UUID over IP
This commit is contained in:
@@ -200,18 +200,34 @@ async function _executeTest(url, options) {
|
||||
async function getHistory(userUuid, userIp) {
|
||||
const db = require('../lib/db');
|
||||
|
||||
// If no identifiers provided, return empty or limit to anonymous?
|
||||
// For strict isolation, we require at least one.
|
||||
// If no identifiers provided, return empty
|
||||
if (!userUuid && !userIp) return [];
|
||||
|
||||
try {
|
||||
const query = `
|
||||
let query;
|
||||
let params;
|
||||
|
||||
// Prioritize UUID if available and valid
|
||||
if (userUuid && userUuid !== 'anonymous') {
|
||||
query = `
|
||||
SELECT * FROM test_results
|
||||
WHERE user_uuid = $1 AND user_ip = $2
|
||||
WHERE user_uuid = $1
|
||||
ORDER BY timestamp DESC
|
||||
LIMIT 50
|
||||
`;
|
||||
const res = await db.pool.query(query, [userUuid, userIp]);
|
||||
params = [userUuid];
|
||||
} else {
|
||||
// Fallback to IP if strictly anonymous
|
||||
query = `
|
||||
SELECT * FROM test_results
|
||||
WHERE user_ip = $1
|
||||
ORDER BY timestamp DESC
|
||||
LIMIT 50
|
||||
`;
|
||||
params = [userIp];
|
||||
}
|
||||
|
||||
const res = await db.pool.query(query, params);
|
||||
|
||||
// Convert DB rows back to simplified history objects
|
||||
return res.rows.map(row => ({
|
||||
|
||||
Reference in New Issue
Block a user