Skip to content

Commit

Permalink
dedup
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Nov 22, 2024
1 parent a9eb280 commit d3dbc5b
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions crates/torii/server/static/sql-playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -516,16 +516,32 @@
setExecutionTime(endTime - startTime);
setResponse(data);

// Add to history with favorite field
// Add to history with deduplication
setQueryHistory((prev) => {
// Find existing query index
const existingIndex = prev.findIndex(item => item.query.trim() === query.trim());

const newEntry = {
query,
timestamp: Date.now(),
rows: data.length,
executionTime: endTime - startTime,
favorite: false
favorite: existingIndex >= 0 ? prev[existingIndex].favorite : false
};
const updated = [newEntry, ...prev.slice(0, 49)];

let updated;
if (existingIndex >= 0) {
// Update existing entry and move to top
updated = [
newEntry,
...prev.slice(0, existingIndex),
...prev.slice(existingIndex + 1)
];
} else {
// Add new entry
updated = [newEntry, ...prev.slice(0, 49)];
}

// Keep favorites at the top
return updated.sort((a, b) => {
if (a.favorite === b.favorite) {
Expand Down

0 comments on commit d3dbc5b

Please sign in to comment.