diff --git a/lib/runner.js b/lib/runner.js index 23e9c3d..4009818 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -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 = ` - SELECT * FROM test_results - WHERE user_uuid = $1 AND user_ip = $2 - ORDER BY timestamp DESC - LIMIT 50 - `; - const res = await db.pool.query(query, [userUuid, userIp]); + let query; + let params; + + // Prioritize UUID if available and valid + if (userUuid && userUuid !== 'anonymous') { + query = ` + 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 return res.rows.map(row => ({