Skip to content

Commit

Permalink
Add support to ObjectBox backend for root statistics
Browse files Browse the repository at this point in the history
Removed v6 -> v7 migrator
Removed `RootManagement`
  • Loading branch information
JaffaKetchup committed Feb 14, 2024
1 parent 9cbaf67 commit 08d6dfc
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 402 deletions.
3 changes: 0 additions & 3 deletions lib/flutter_map_tile_caching.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import 'package:isar/isar.dart';
import 'package:latlong2/latlong.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';
import 'package:stream_transform/stream_transform.dart';
import 'package:watcher/watcher.dart';

Expand All @@ -38,7 +37,6 @@ import 'src/bulk_download/instance.dart';
import 'src/bulk_download/rate_limited_stream.dart';
import 'src/bulk_download/tile_loops/shared.dart';
import 'src/errors/browsing.dart';
import 'src/misc/exts.dart';
import 'src/misc/int_extremes.dart';
import 'src/misc/obscure_query_params.dart';
import 'src/providers/image_provider.dart';
Expand All @@ -64,7 +62,6 @@ part 'src/regions/recovered_region.dart';
part 'src/regions/rectangle.dart';
part 'src/root/directory.dart';
part 'src/root/import.dart';
part 'src/root/manage.dart';
part 'src/root/migrator.dart';
part 'src/root/recovery.dart';
part 'src/root/statistics.dart';
Expand Down
14 changes: 13 additions & 1 deletion lib/src/backend/impls/objectbox/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class _ObjectBoxBackendImpl implements FMTCObjectBoxBackendInternal {

Future<Map<String, dynamic>?> _sendCmd({
required _WorkerCmdType type,
required Map<String, dynamic> args,
Map<String, dynamic> args = const {},
}) async {
expectInitialised;

Expand Down Expand Up @@ -199,6 +199,18 @@ class _ObjectBoxBackendImpl implements FMTCObjectBoxBackendInternal {
FMTCBackendAccess.internal = null;
}

@override
Future<List<String>> listStores() async =>
(await _sendCmd(type: _WorkerCmdType.storeExists))!['stores'];

@override
Future<double> rootSize() async =>
(await _sendCmd(type: _WorkerCmdType.rootSize))!['size'];

@override
Future<int> rootLength() async =>
(await _sendCmd(type: _WorkerCmdType.rootLength))!['length'];

@override
Future<bool> storeExists({
required String storeName,
Expand Down
38 changes: 38 additions & 0 deletions lib/src/backend/impls/objectbox/worker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ part of 'backend.dart';
enum _WorkerCmdType {
initialise_, // Only valid as a response
destroy_, // Only valid as a request
listStores,
rootSize,
rootLength,
storeExists,
createStore,
resetStore,
Expand Down Expand Up @@ -132,6 +135,41 @@ Future<void> _worker(

// TODO: Consider final message
Isolate.exit();
case _WorkerCmdType.listStores:
final query = root
.box<ObjectBoxStore>()
.query()
.build()
.property(ObjectBoxStore_.name);

sendRes(id: cmd.id, data: {'stores': query.find()});

query.close();

break;
case _WorkerCmdType.rootSize:
final query = root
.box<ObjectBoxStore>()
.query()
.build()
.property(ObjectBoxStore_.size);

sendRes(
id: cmd.id,
data: {'size': query.find().sum / 1024}, // Convert to KiB
);

query.close();

break;
case _WorkerCmdType.rootLength:
final query = root.box<ObjectBoxTile>().query().build();

sendRes(id: cmd.id, data: {'length': query.count()});

query.close();

break;
case _WorkerCmdType.storeExists:
final query = root
.box<ObjectBoxStore>()
Expand Down
16 changes: 16 additions & 0 deletions lib/src/backend/interfaces/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ abstract interface class FMTCBackendInternal with FMTCBackendAccess {
/// initialised.
Directory? get rootDirectory;

/// {@template fmtc.backend.listStores}
/// List all the available stores
/// {@endtemplate}
Future<List<String>> listStores();

/// {@template fmtc.backend.rootSize}
/// Retrieve the total number of KiBs of all tiles' bytes (not 'real total'
/// size) from all stores
/// {@endtemplate}
Future<double> rootSize();

/// {@template fmtc.backend.rootLength}
/// Retrieve the total number of tiles in all stores
/// {@endtemplate}
Future<int> rootLength();

/// {@template fmtc.backend.storeExists}
/// Check whether the specified store currently exists
/// {@endtemplate}
Expand Down
29 changes: 0 additions & 29 deletions lib/src/misc/exts.dart

This file was deleted.

13 changes: 5 additions & 8 deletions lib/src/root/directory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,16 @@ only. It will be removed in a future version.
)
typedef RootDirectory = FMTCRoot;

/// Provides access to management, statistics, recovery, migration (and the
/// import functionality) on the intitialised root.
/// Provides access to statistics, recovery, migration (and the import
/// functionality) on the intitialised root.
///
/// Management services are not provided here, instead use methods on the backend
/// directly.
///
/// Note that this does not provide direct access to any [FMTCStore]s.
abstract class FMTCRoot {
const FMTCRoot._();

/// Manage the root's representation on the filesystem
///
/// To create, initialise FMTC. Assume that FMTC is ready after initialisation
/// and before [RootManagement.delete] is called.
static RootManagement get manage => const RootManagement._();

/// Get statistics about this root (and all sub-stores)
static RootStats get stats => const RootStats._();

Expand Down
45 changes: 0 additions & 45 deletions lib/src/root/manage.dart

This file was deleted.

Loading

0 comments on commit 08d6dfc

Please sign in to comment.