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) {
|
async function getHistory(userUuid, userIp) {
|
||||||
const db = require('../lib/db');
|
const db = require('../lib/db');
|
||||||
|
|
||||||
// If no identifiers provided, return empty or limit to anonymous?
|
// If no identifiers provided, return empty
|
||||||
// For strict isolation, we require at least one.
|
|
||||||
if (!userUuid && !userIp) return [];
|
if (!userUuid && !userIp) return [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const query = `
|
let query;
|
||||||
SELECT * FROM test_results
|
let params;
|
||||||
WHERE user_uuid = $1 AND user_ip = $2
|
|
||||||
ORDER BY timestamp DESC
|
// Prioritize UUID if available and valid
|
||||||
LIMIT 50
|
if (userUuid && userUuid !== 'anonymous') {
|
||||||
`;
|
query = `
|
||||||
const res = await db.pool.query(query, [userUuid, userIp]);
|
SELECT * FROM test_results
|
||||||
|
WHERE user_uuid = $1
|
||||||
|
ORDER BY timestamp DESC
|
||||||
|
LIMIT 50
|
||||||
|
`;
|
||||||
|
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
|
// Convert DB rows back to simplified history objects
|
||||||
return res.rows.map(row => ({
|
return res.rows.map(row => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user