Skip to content

Commit 43542aa

Browse files
authored
refactor: remove dead AppState.History and ServiceEarning.Delta (#48)
Both were populated/computed on every GetAppState but never read by the frontend (they existed only in the type contract, never accessed). AppState.History ran a 200-row ListEarningsHistory query on every state read — now removed, which also drops the query from the frequent event-driven refresh added recently. Removed the now-orphaned store.ListEarningsHistory (its only caller) and trimmed its test to keep the ListLatestEarnings coverage. Removed the dead fields from the frontend bindings (wails.d.ts, models.ts) to keep the type contract in sync. Verified: go build/vet/test -race and the frontend tsc && vite build all pass.
1 parent 588cddc commit 43542aa

5 files changed

Lines changed: 1 addition & 48 deletions

File tree

app.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ type AppState struct {
149149
Services []catalog.Service `json:"services"`
150150
Deployments []store.Deployment `json:"deployments"`
151151
Earnings []store.EarningsRecord `json:"earnings"`
152-
History []store.EarningsRecord `json:"history"`
153152
Guides []runtime.InstallGuide `json:"guides"`
154153
Notifications []Notification `json:"notifications"`
155154
Currencies []string `json:"currencies"`
@@ -189,7 +188,6 @@ type ServiceEarning struct {
189188
Currency string `json:"currency"`
190189
BalanceDisplay float64 `json:"balanceDisplay"`
191190
Convertible bool `json:"convertible"`
192-
Delta float64 `json:"delta"`
193191
Error string `json:"error"`
194192
Cashout CashoutProgress `json:"cashout"`
195193
}
@@ -272,7 +270,6 @@ func (a *App) GetAppState() (AppState, error) {
272270
Services: a.catalog.ListVisible(),
273271
Deployments: a.store.ListDeployments(),
274272
Earnings: a.store.ListLatestEarnings(),
275-
History: a.store.ListEarningsHistory(200),
276273
Guides: runtime.InstallGuides(),
277274
Notifications: a.notifications(runtimeStatus),
278275
Currencies: supportedCurrencies(),
@@ -489,10 +486,6 @@ func (a *App) computeEarningsSummary() EarningsSummary {
489486
se.BalanceDisplay = conv
490487
}
491488
}
492-
// Native day-over-day change from the last two collected days.
493-
if days := daysByPlat[rec.Platform]; len(days) >= 2 {
494-
se.Delta = perPlat[rec.Platform][days[len(days)-1]] - perPlat[rec.Platform][days[len(days)-2]]
495-
}
496489
cp := CashoutProgress{
497490
MinAmount: cash.MinAmount,
498491
Currency: cash.Currency,

frontend/src/wails.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export interface AppState {
2727
services: Service[];
2828
deployments: Deployment[] | null;
2929
earnings: EarningsRecord[] | null;
30-
history: EarningsRecord[] | null;
3130
guides: InstallGuide[];
3231
notifications: NotificationItem[];
3332
currencies: string[];
@@ -55,7 +54,6 @@ export interface ServiceEarning {
5554
currency: string;
5655
balanceDisplay: number;
5756
convertible: boolean;
58-
delta: number;
5957
error: string;
6058
cashout: CashoutProgress;
6159
}

frontend/wailsjs/go/models.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ export namespace main {
309309
services: catalog.Service[];
310310
deployments: store.Deployment[];
311311
earnings: store.EarningsRecord[];
312-
history: store.EarningsRecord[];
313312
guides: runtime.InstallGuide[];
314313
notifications: Notification[];
315314
currencies: string[];
@@ -325,7 +324,6 @@ export namespace main {
325324
this.services = this.convertValues(source["services"], catalog.Service);
326325
this.deployments = this.convertValues(source["deployments"], store.Deployment);
327326
this.earnings = this.convertValues(source["earnings"], store.EarningsRecord);
328-
this.history = this.convertValues(source["history"], store.EarningsRecord);
329327
this.guides = this.convertValues(source["guides"], runtime.InstallGuide);
330328
this.notifications = this.convertValues(source["notifications"], Notification);
331329
this.currencies = source["currencies"];

internal/store/store.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -262,33 +262,6 @@ func (s *Store) ListLatestEarnings() []EarningsRecord {
262262
return out
263263
}
264264

265-
func (s *Store) ListEarningsHistory(limit int) []EarningsRecord {
266-
if limit <= 0 {
267-
limit = 200
268-
}
269-
rows, err := s.db.Query(`
270-
SELECT platform, balance, currency, error, created_at
271-
FROM earnings
272-
ORDER BY created_at DESC
273-
LIMIT ?
274-
`, limit)
275-
if err != nil {
276-
return nil
277-
}
278-
defer rows.Close()
279-
var out []EarningsRecord
280-
for rows.Next() {
281-
var record EarningsRecord
282-
if err := rows.Scan(&record.Platform, &record.Balance, &record.Currency, &record.Error, &record.CreatedAt); err == nil {
283-
out = append(out, record)
284-
}
285-
}
286-
for i, j := 0, len(out)-1; i < j; i, j = i+1, j-1 {
287-
out[i], out[j] = out[j], out[i]
288-
}
289-
return out
290-
}
291-
292265
// ListDailyBalances returns the latest successful balance (rows whose error column
293266
// is empty) for each (platform, day) over the last daysBack days. The latest row
294267
// per (platform, day) is chosen by MAX(id), not MAX(created_at): created_at is

internal/store/store_test.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ func TestDeploymentRoundTrip(t *testing.T) {
367367
}
368368
}
369369

370-
func TestEarningsLatestAndHistory(t *testing.T) {
370+
func TestEarningsLatest(t *testing.T) {
371371
s := openTestStore(t)
372372

373373
if _, err := s.SaveEarnings(EarningsRecord{Platform: "storj", Balance: 1.0, Currency: "USD", CreatedAt: "2026-01-01T00:00:00Z"}); err != nil {
@@ -384,15 +384,6 @@ func TestEarningsLatestAndHistory(t *testing.T) {
384384
if latest[0].Balance != 2.5 {
385385
t.Fatalf("expected the latest balance 2.5, got %v", latest[0].Balance)
386386
}
387-
388-
history := s.ListEarningsHistory(10)
389-
if len(history) != 2 {
390-
t.Fatalf("expected 2 history records, got %d", len(history))
391-
}
392-
// History is reversed to oldest-first.
393-
if history[0].Balance != 1.0 || history[1].Balance != 2.5 {
394-
t.Fatalf("unexpected history order: %+v", history)
395-
}
396387
}
397388

398389
// TestListLatestEarningsTieBreakByID pins the deterministic intra-second

0 commit comments

Comments
 (0)