From a3d235bd3989cc1cb43bac0bc623ce4e50d64a56 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Mon, 3 Aug 2026 23:18:23 -0700 Subject: [PATCH] remove dead code --- src/PortfolioData.zig | 6 +----- src/commands/common.zig | 8 ++------ src/service.zig | 43 +++++------------------------------------ 3 files changed, 8 insertions(+), 49 deletions(-) diff --git a/src/PortfolioData.zig b/src/PortfolioData.zig index 475227a..adba403 100644 --- a/src/PortfolioData.zig +++ b/src/PortfolioData.zig @@ -709,11 +709,7 @@ pub fn load( var load_all = self.svc.loadAllPrices( syms, watch_syms_list.items, - .{ - .force_refresh = opts.fetch_options.force_refresh, - .skip_network = opts.fetch_options.skip_network, - .color = false, // pd doesn't render; caller's progress callback owns UI. - }, + opts.fetch_options, opts.aggregate_progress, sym_cb, ); diff --git a/src/commands/common.zig b/src/commands/common.zig index 787ff71..29a0f91 100644 --- a/src/commands/common.zig +++ b/src/commands/common.zig @@ -295,7 +295,7 @@ pub fn loadPortfolioPrices( .grand_total = (if (portfolio_syms) |ps| ps.len else 0) + watch_syms.len, }; - // Map RefreshPolicy -> LoadAllConfig: + // `fetchOptionsFromPolicy` maps the flag; what each policy means here: // .force -> ignore TTL; incremental candle top-up (no wipe). // .auto -> respect TTL, fetch on stale. // .never -> offline mode: never touch the network. Stale cache @@ -303,11 +303,7 @@ pub fn loadPortfolioPrices( const result = svc.loadAllPrices( portfolio_syms, watch_syms, - .{ - .force_refresh = refresh == .force, - .skip_network = refresh == .never, - .color = color, - }, + fetchOptionsFromPolicy(refresh), aggregate.callback(), symbol_progress.callback(), ); diff --git a/src/service.zig b/src/service.zig index bfbc805..f1d6343 100644 --- a/src/service.zig +++ b/src/service.zig @@ -2122,22 +2122,6 @@ pub const DataService = struct { // ── Consolidated Price Loading (Parallel Server + Sequential Provider) ── /// Configuration for loadAllPrices. - pub const LoadAllConfig = struct { - force_refresh: bool = false, - /// Skip provider fetches and server sync. Returns cached - /// data (even if stale) and treats cache miss as failure. - /// Drives `--refresh-data=never`. - skip_network: bool = false, - color: bool = true, - - /// Map this config to the per-call `FetchOptions` shape. - /// Convenience for paths that need to pass through to - /// `getCandles`/`getDividends`/etc. - pub fn fetchOptions(self: LoadAllConfig) FetchOptions { - return .{ .skip_network = self.skip_network, .force_refresh = self.force_refresh }; - } - }; - /// Result of loadAllPrices operation. pub const LoadAllResult = struct { prices: std.StringHashMap(f64), @@ -2217,7 +2201,7 @@ pub const DataService = struct { self: *DataService, portfolio_syms: ?[]const []const u8, watch_syms: []const []const u8, - config: LoadAllConfig, + opts: FetchOptions, aggregate_progress: ?AggregateProgressCallback, symbol_progress: ?ProgressCallback, ) LoadAllResult { @@ -2248,7 +2232,7 @@ pub const DataService = struct { for (watch_syms) |sym| all_symbols.append(self.allocator, sym) catch |err| log.warn("loadAllPrices append watch sym({s}): {t}", .{ sym, err }); // force_refresh does NOT wipe the candle cache. It flows - // through to getCandles (via config.fetchOptions()), which + // through to getCandles (the same `opts` we were handed), which // ignores the TTL and does an incremental top-up - see the // `--refresh-data=force` contract. The Phase-1 fast path below // is skipped on force_refresh so every symbol is re-validated @@ -2262,7 +2246,7 @@ pub const DataService = struct { if (aggregate_progress) |p| p.emit(0, total_count, .cache_check); for (all_symbols.items) |sym| { - if (!config.force_refresh and self.isCandleCacheFresh(sym)) { + if (!opts.force_refresh and self.isCandleCacheFresh(sym)) { if (self.getCachedLastClose(sym)) |close| { result.prices.put(sym, close) catch |err| log.warn("loadAllPrices cache-hit put({s}): {t}", .{ sym, err }); self.updateLatestDate(&result, sym); @@ -2283,7 +2267,7 @@ pub const DataService = struct { // Offline mode: skip server sync and provider fetch entirely. // For symbols without a fresh cache, fall back to stale cache // before giving up. - if (config.skip_network) { + if (opts.skip_network) { for (needs_fetch.items) |sym| { if (self.getCachedLastClose(sym)) |close| { result.prices.put(sym, close) catch |err| log.warn("loadAllPrices cache-hit put({s}): {t}", .{ sym, err }); @@ -2329,7 +2313,7 @@ pub const DataService = struct { &result, symbol_progress, total_count - server_failures.items.len, // offset for progress display - config.fetchOptions(), + opts, ); } @@ -3572,23 +3556,6 @@ test "FetchOptions default is fully permissive" { try std.testing.expect(!opts.force_refresh); } -test "LoadAllConfig.fetchOptions maps fields through" { - const cfg = DataService.LoadAllConfig{ - .force_refresh = true, - .skip_network = false, - }; - const opts = cfg.fetchOptions(); - try std.testing.expect(opts.force_refresh); - try std.testing.expect(!opts.skip_network); - - const cfg2 = DataService.LoadAllConfig{ - .skip_network = true, - }; - const opts2 = cfg2.fetchOptions(); - try std.testing.expect(opts2.skip_network); - try std.testing.expect(!opts2.force_refresh); -} - test "getCandles offline mode returns cached data without network" { const allocator = std.testing.allocator; const io = std.testing.io;