Skip to content

Commit

Permalink
feat: move JumpGate into the db
Browse files Browse the repository at this point in the history
  • Loading branch information
eseidel committed Feb 18, 2024
1 parent dd5f860 commit f7d76ec
Show file tree
Hide file tree
Showing 35 changed files with 162 additions and 153 deletions.
3 changes: 2 additions & 1 deletion packages/cli/bin/deals_nearby.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ Future<void> cliMain(FileSystem fs, ArgResults argResults) async {

final systemsCache = SystemsCache.load(fs)!;
final marketListings = await MarketListingSnapshot.load(db);
final jumpGates = JumpGateCache.load(fs);
final jumpGates = await JumpGateSnapshot.load(db);
final constructionSnapshot = await ConstructionSnapshot.load(db);
// Can't use loadSystemConnectivity because need constructionSnapshot later.
final systemConnectivity =
SystemConnectivity.fromJumpGates(jumpGates, constructionSnapshot);
final routePlanner = RoutePlanner.fromSystemsCache(
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/bin/find_mounts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
final db = await defaultDatabase();
final marketPrices = await MarketPrices.load(db);
final systemsCache = SystemsCache.load(fs)!;
final jumpGateCache = JumpGateCache.load(fs);
final constructionSnapshot = await ConstructionSnapshot.load(db);
final systemConnectivity =
SystemConnectivity.fromJumpGates(jumpGateCache, constructionSnapshot);
final systemConnectivity = await loadSystemConnectivity(db);
final routePlanner = RoutePlanner.fromSystemsCache(
systemsCache,
systemConnectivity,
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/bin/fleet_closest_to.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
final systemsCache = SystemsCache.load(fs)!;
final marketListings = await MarketListingSnapshot.load(db);

final jumpGateCache = JumpGateCache.load(fs);
final constructionSnapshot = await ConstructionSnapshot.load(db);
final systemConnectivity =
SystemConnectivity.fromJumpGates(jumpGateCache, constructionSnapshot);
final systemConnectivity = await loadSystemConnectivity(db);
final routePlanner = RoutePlanner.fromSystemsCache(
systemsCache,
systemConnectivity,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/bin/idle_queue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
if (count++ % printEvery == 0) {
logger.info('$queue');
}
await queue.runOne(api, caches);
await queue.runOne(db, api, caches);
}

// required or main() will hang
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/bin/jumpgate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
.symbol;

final constructionSnapshot = await ConstructionSnapshot.load(db);
final jumpGateCache = JumpGateCache.load(fs);
final jumpGate = await jumpGateCache.getOrFetch(api, jumpGateSymbol);
final jumpGate = await getOrFetchJumpGate(db, api, jumpGateSymbol);

String statusString(WaypointSymbol jumpGateSymbol) {
final isUnderConstruction =
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/bin/jumpgate_construction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {

final systemsCache = SystemsCache.load(fs)!;

// Can't use loadSystemConnectivity because need constructionSnapshot later.
final constructionSnapshot = await ConstructionSnapshot.load(db);
final jumpGateCache = JumpGateCache.load(fs);
final jumpGateSnapshot = await JumpGateSnapshot.load(db);
final systemConnectivity =
SystemConnectivity.fromJumpGates(jumpGateCache, constructionSnapshot);
SystemConnectivity.fromJumpGates(jumpGateSnapshot, constructionSnapshot);

// Find all reachable jumpgates that are under construction.
final systemSymbols =
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/bin/jumpgates_to_scan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
final db = await defaultDatabase();
final systemSymbol = await myHqSystemSymbol(db);
final systemsCache = SystemsCache.load(fs)!;
final jumpGateCache = JumpGateCache.load(fs);
final jumpGateSnapshot = await JumpGateSnapshot.load(db);
final constructionSnapshot = await ConstructionSnapshot.load(db);
final chartingSnapshot = await ChartingSnapshot.load(db);

Expand All @@ -22,7 +22,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
while (systems.isNotEmpty || jumpGates.isNotEmpty) {
if (jumpGates.isNotEmpty) {
final from = jumpGates.take();
final fromRecord = jumpGateCache.recordForSymbol(from.value);
final fromRecord = jumpGateSnapshot.recordForSymbol(from.value);
if (fromRecord == null) {
final chartingRecord = chartingSnapshot.getRecord(from.value);
if (chartingRecord == null) {
Expand All @@ -32,7 +32,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
}
continue;
}
if (!canJumpFrom(jumpGateCache, constructionSnapshot, from.value)) {
if (!canJumpFrom(jumpGateSnapshot, constructionSnapshot, from.value)) {
continue;
}
for (final to in fromRecord.connections) {
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/bin/market_feeder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
final marketListings = await MarketListingSnapshot.load(db);

final marketPrices = await MarketPrices.load(db);
final jumpGateCache = JumpGateCache.load(fs);
final constructionSnapshot = await ConstructionSnapshot.load(db);
final systemConnectivity =
SystemConnectivity.fromJumpGates(jumpGateCache, constructionSnapshot);
final systemConnectivity = await loadSystemConnectivity(db);
final routePlanner = RoutePlanner.fromSystemsCache(
systemsCache,
systemConnectivity,
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/bin/market_nearby_buys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
final db = await defaultDatabase();
final marketPrices = await MarketPrices.load(db);
final systemsCache = SystemsCache.load(fs)!;
final jumpGateCache = JumpGateCache.load(fs);
final constructionSnapshot = await ConstructionSnapshot.load(db);
final systemConnectivity =
SystemConnectivity.fromJumpGates(jumpGateCache, constructionSnapshot);
final systemConnectivity = await loadSystemConnectivity(db);
final routePlanner = RoutePlanner.fromSystemsCache(
systemsCache,
systemConnectivity,
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/bin/market_nearby_sells.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
final db = await defaultDatabase();
final marketPrices = await MarketPrices.load(db);
final systemsCache = SystemsCache.load(fs)!;
final jumpGateCache = JumpGateCache.load(fs);
final constructionSnapshot = await ConstructionSnapshot.load(db);
final systemConnectivity =
SystemConnectivity.fromJumpGates(jumpGateCache, constructionSnapshot);
final systemConnectivity = await loadSystemConnectivity(db);
final routePlanner = RoutePlanner.fromSystemsCache(
systemsCache,
systemConnectivity,
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/bin/routing_plan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
throw UnimplementedError();
}

final jumpGateCache = JumpGateCache.load(fs);
final constructionSnapshot = await ConstructionSnapshot.load(db);
final systemConnectivity =
SystemConnectivity.fromJumpGates(jumpGateCache, constructionSnapshot);
final systemConnectivity = await loadSystemConnectivity(db);
final routePlanner = RoutePlanner.fromSystemsCache(
systemsCache,
systemConnectivity,
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/bin/simulate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
final db = await defaultDatabase();
final marketPrices = await MarketPrices.load(db);
final systemsCache = SystemsCache.load(fs)!;
final jumpGateCache = JumpGateCache.load(fs);
final constructionSnapshot = await ConstructionSnapshot.load(db);
final systemConnectivity =
SystemConnectivity.fromJumpGates(jumpGateCache, constructionSnapshot);
final systemConnectivity = await loadSystemConnectivity(db);
final routePlanner = RoutePlanner.fromSystemsCache(
systemsCache,
systemConnectivity,
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/bin/static_cache_find_missing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
final db = await defaultDatabase();
final marketPrices = await MarketPrices.load(db);
final systemsCache = SystemsCache.load(fs)!;
final jumpGateCache = JumpGateCache.load(fs);
final constructionSnapshot = await ConstructionSnapshot.load(db);
final systemConnectivity =
SystemConnectivity.fromJumpGates(jumpGateCache, constructionSnapshot);
final systemConnectivity = await loadSystemConnectivity(db);
final routePlanner = RoutePlanner.fromSystemsCache(
systemsCache,
systemConnectivity,
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/bin/system_routing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
final hqSystemSymbol = await myHqSystemSymbol(db);
final marketListings = await MarketListingSnapshot.load(db);
final shipyardListings = ShipyardListingCache.load(fs);
final jumpGateCache = JumpGateCache.load(fs);
final constructionSnapshot = await ConstructionSnapshot.load(db);
final systemConnectivity =
SystemConnectivity.fromJumpGates(jumpGateCache, constructionSnapshot);
final systemConnectivity = await loadSystemConnectivity(db);
final routePlanner = RoutePlanner.fromSystemsCache(
systems,
systemConnectivity,
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/bin/system_stats.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {

logger.info('Starting from $startSystemSymbol, known reachable:');
final systemsCache = SystemsCache.load(fs)!;
final jumpGateCache = JumpGateCache.load(fs);
// Can't use loadSystemConnectivity because need jumpGateSnapshot later.
final jumpGateSnapshot = await JumpGateSnapshot.load(db);
final constructionSnapshot = await ConstructionSnapshot.load(db);
final systemConnectivity =
SystemConnectivity.fromJumpGates(jumpGateCache, constructionSnapshot);
SystemConnectivity.fromJumpGates(jumpGateSnapshot, constructionSnapshot);

final reachableSystems =
systemConnectivity.systemsReachableFrom(startSystemSymbol).toSet();
Expand Down Expand Up @@ -92,7 +93,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {

// How many are cached?
var cachedJumpGates = 0;
for (final record in jumpGateCache.values) {
for (final record in jumpGateSnapshot.values) {
// We could sort first by system to save ourselves some lookups.
final systemSymbol = record.waypointSymbol.system;
if (reachableSystems.contains(systemSymbol)) {
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/bin/system_to_chart_next.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
construction,
staticCaches.waypointTraits,
);
final jumpGateCache = JumpGateCache.load(fs);
final constructionSnapshot = await ConstructionSnapshot.load(db);
final systemConnectivity =
SystemConnectivity.fromJumpGates(jumpGateCache, constructionSnapshot);
final systemConnectivity = await loadSystemConnectivity(db);

final shipCache = ShipCache.load(fs)!;
final behaviorCache = BehaviorCache.load(fs);
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/bin/systems_explored.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
'with market prices.',
);

final jumpGateCache = JumpGateCache.load(fs);
final constructionSnapshot = await ConstructionSnapshot.load(db);
final systemConnectivity =
SystemConnectivity.fromJumpGates(jumpGateCache, constructionSnapshot);
final systemConnectivity = await loadSystemConnectivity(db);
final hqSystemSymbol = await myHqSystemSymbol(db);
final reachableSystems =
systemConnectivity.systemsReachableFrom(hqSystemSymbol);
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/bin/systems_interesting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {

final systemsCache = SystemsCache.load(fs)!;
final constructionSnapshot = await ConstructionSnapshot.load(db);
final jumpGateCache = JumpGateCache.load(fs);
final jumpGateSnapshot = await JumpGateSnapshot.load(db);
final systemConnectivity =
SystemConnectivity.fromJumpGates(jumpGateCache, constructionSnapshot);
SystemConnectivity.fromJumpGates(jumpGateSnapshot, constructionSnapshot);
final hqSystemSymbol = await myHqSystemSymbol(db);
final reachableSystems =
systemConnectivity.systemsReachableFrom(hqSystemSymbol).toSet();
Expand All @@ -41,7 +41,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
}
logger.info('of ${interestingSystemSymbols.length} interesting systems.');

final reachableJumpGates = jumpGateCache.values.where(
final reachableJumpGates = jumpGateSnapshot.values.where(
(record) => reachableSystems.contains(record.waypointSymbol.system),
);
// These are not necessarily reachable (the jump gate on either side might
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/bin/systems_nearby.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
await startSystemFromArg(db, argResults.rest.firstOrNull);

final marketListings = await MarketListingSnapshot.load(db);
final jumpGateCache = JumpGateCache.load(fs);
final constructionSnapshot = await ConstructionSnapshot.load(db);
final systemConnectivity =
SystemConnectivity.fromJumpGates(jumpGateCache, constructionSnapshot);
final systemConnectivity = await loadSystemConnectivity(db);

final connectedSystemSymbols =
systemConnectivity.directlyConnectedSystemSymbols(startSystemSymbol);
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/bin/systems_to_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
final startSystemSymbol =
await startSystemFromArg(db, argResults.rest.firstOrNull);

final jumpGateCache = JumpGateCache.load(fs);
final constructionSnapshot = await ConstructionSnapshot.load(db);
final systemConnectivity =
SystemConnectivity.fromJumpGates(jumpGateCache, constructionSnapshot);
final systemConnectivity = await loadSystemConnectivity(db);
final systemsCache = SystemsCache.load(fs)!;
final chartingSnapshot = await ChartingSnapshot.load(db);

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/bin/systems_to_warp_to.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
final startSystemSymbol = await myHqSystemSymbol(db);

final staticCaches = StaticCaches.load(fs);
final jumpGateCache = JumpGateCache.load(fs);
final jumpGateSnapshot = await JumpGateSnapshot.load(db);
final constructionCache = ConstructionCache(db);
final systemConnectivity = SystemConnectivity.fromJumpGates(
jumpGateCache,
jumpGateSnapshot,
await constructionCache.snapshot(),
);
final systemsCache = SystemsCache.load(fs)!;
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/lib/cache/caches.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Caches {
final WaypointCache waypoints;

/// The cache of jump gates.
final JumpGateCache jumpGates;
final JumpGateSnapshot jumpGates;

/// The cache of markets descriptions.
/// This is currently updated at the top of every loop.
Expand Down Expand Up @@ -155,7 +155,7 @@ class Caches {
await ContractCache.loadOrFetch(api, fs: fs, forceRefresh: true);
final behaviors = BehaviorCache.load(fs);

final jumpGates = JumpGateCache.load(fs);
final jumpGates = await JumpGateSnapshot.load(db);
final constructionSnapshot = await ConstructionSnapshot.load(db);
final systemConnectivity =
SystemConnectivity.fromJumpGates(jumpGates, constructionSnapshot);
Expand Down
Loading

0 comments on commit f7d76ec

Please sign in to comment.