Skip to content

Commit 094db90

Browse files
committed
fix: address Copilot review on #64
- Serialize log-source saves so a slow/failing earlier request can't revert UI state after a later request has already succeeded with overlapping state. saveLogSourcesNow now chains onto the previous save's settlement; the state being POSTed is read at dequeue time so any reverts done in an earlier caller's catch block are visible to the next save. - Update GetEnabledLogSourcesByServerID doc comment — it still said "no HAProxy configuration" after the schema rename to boxes/box_id.
1 parent 996a19d commit 094db90

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

gearbox/internal/framework/database/log_sources.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ func (d *DB) GetEnabledLogSources(haproxyID int64) ([]LogSourceSetting, error) {
4343
return sources, rows.Err()
4444
}
4545

46-
// GetEnabledLogSourcesByServerID returns enabled log sources for a server by its server_id.
47-
// Returns empty slice (not error) if the server has no HAProxy configuration or no log sources.
46+
// GetEnabledLogSourcesByServerID returns enabled log sources for a box by its
47+
// box_id (the human-readable string identifier, e.g. "light-hugger").
48+
// Returns empty slice (not error) if no box matches or the box has no log sources.
4849
func (d *DB) GetEnabledLogSourcesByServerID(serverID string) ([]LogSourceSetting, error) {
4950
d.mu.RLock()
5051
defer d.mu.RUnlock()

gearbox/static/js/gears/logs-config.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,22 @@
4040
.map(input => input.value);
4141
}
4242

43-
async function saveLogSourcesNow() {
43+
// Serialize saves so a slow/failing earlier request can't revert UI state
44+
// after a later request has already succeeded with overlapping state.
45+
// Each call chains onto the previous save's settlement; the state being
46+
// POSTed is read at dequeue time, so by the time a later save runs it
47+
// sees any reverts the earlier save's caller performed in its catch block.
48+
let saveQueue = Promise.resolve();
49+
50+
function saveLogSourcesNow() {
51+
const next = saveQueue
52+
.catch(() => {}) // don't let a prior rejection break the chain
53+
.then(() => postLogSources());
54+
saveQueue = next;
55+
return next;
56+
}
57+
58+
async function postLogSources() {
4459
const root = document.getElementById('logs-config-root');
4560
if (!root) return;
4661
const url = root.dataset.saveUrl;

0 commit comments

Comments
 (0)