mirror of
https://github.com/zapstore/zapstore.git
synced 2026-10-05 20:48:24 +00:00
DB version check and initializer improvements
This commit is contained in:
+1
-1
@@ -13,7 +13,7 @@ import 'package:zapstore/utils/debounce.dart';
|
||||
import 'package:zapstore/utils/theme.dart';
|
||||
import 'package:zapstore/widgets/error_container.dart';
|
||||
|
||||
const kDbVersion = 1;
|
||||
const kDbVersion = 2;
|
||||
final appLinks = AppLinks();
|
||||
|
||||
/// Application entry point.
|
||||
|
||||
+7
-7
@@ -169,7 +169,7 @@ class App extends BaseApp with DataModelMixin<App> {
|
||||
}
|
||||
|
||||
mixin AppAdapter on Adapter<App> {
|
||||
final _queriedAtMap = <String, DateTime>{};
|
||||
final queriedAtMap = <String, DateTime>{};
|
||||
|
||||
@override
|
||||
Future<List<App>> findAll(
|
||||
@@ -217,9 +217,9 @@ mixin AppAdapter on Adapter<App> {
|
||||
final identifiers = <String>{...params['#d']};
|
||||
|
||||
final cachedIdentifiers =
|
||||
identifiers.where((i) => _queriedAtMap.containsKey(i));
|
||||
identifiers.where((i) => queriedAtMap.containsKey(i));
|
||||
final newIdentifiers =
|
||||
identifiers.where((i) => !_queriedAtMap.containsKey(i));
|
||||
identifiers.where((i) => !queriedAtMap.containsKey(i));
|
||||
|
||||
var cachedApps = <App>[];
|
||||
var newApps = <App>[];
|
||||
@@ -227,9 +227,9 @@ mixin AppAdapter on Adapter<App> {
|
||||
// For apps already in cache, find earliest date of the set
|
||||
// (as we cannot have one `since` per app)
|
||||
if (cachedIdentifiers.isNotEmpty) {
|
||||
earliestQueryAt = cachedIdentifiers.fold<DateTime>(
|
||||
_queriedAtMap[cachedIdentifiers.first]!, (acc, e) {
|
||||
return acc.isBefore(_queriedAtMap[e]!) ? acc : _queriedAtMap[e]!;
|
||||
earliestQueryAt = cachedIdentifiers
|
||||
.fold<DateTime>(queriedAtMap[cachedIdentifiers.first]!, (acc, e) {
|
||||
return acc.isBefore(queriedAtMap[e]!) ? acc : queriedAtMap[e]!;
|
||||
});
|
||||
|
||||
cachedApps = await super.findAll(
|
||||
@@ -297,7 +297,7 @@ mixin AppAdapter on Adapter<App> {
|
||||
|
||||
if (m != null) {
|
||||
for (final app in apps) {
|
||||
_queriedAtMap[app.identifier] = m;
|
||||
queriedAtMap[app.identifier] = m;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,12 @@ final appInitializer = FutureProvider<void>((ref) async {
|
||||
// Initialize Flutter Data
|
||||
await ref.read(initializeFlutterData(adapterProvidersMap).future);
|
||||
|
||||
// Check DB version
|
||||
final userDbVersion = ref.settings.findOneLocalById('_')!.dbVersion;
|
||||
if (userDbVersion < kDbVersion) {
|
||||
await ref.read(localStorageProvider).destroy();
|
||||
}
|
||||
|
||||
// Initialize relays
|
||||
final relay = ref.read(relayMessageNotifierProvider(kAppRelays).notifier);
|
||||
final socialRelays =
|
||||
@@ -50,10 +56,12 @@ final appInitializer = FutureProvider<void>((ref) async {
|
||||
);
|
||||
|
||||
// Load curation sets (here for now)
|
||||
await ref.appCurationSets.findAll();
|
||||
if (ref.appCurationSets.countLocal == 0) {
|
||||
await ref.appCurationSets.findAll();
|
||||
|
||||
// Preload zapstore's nostr curation set
|
||||
await ref.read(appCurationSetProvider(kNostrCurationSet).future);
|
||||
// Preload zapstore's nostr curation set
|
||||
await ref.read(appCurationSetProvider(kNostrCurationSet).future);
|
||||
}
|
||||
|
||||
// Preload latest releases
|
||||
await ref.read(latestReleasesAppProvider.notifier).fetch();
|
||||
@@ -65,7 +73,7 @@ final appInitializer = FutureProvider<void>((ref) async {
|
||||
final appLinksSub = appLinks.uriLinkStream.listen((uri) async {
|
||||
if (uri.scheme == "zapstore") {
|
||||
final adapter = ref.apps.appAdapter;
|
||||
final App? app = await adapter.findOne(uri.host);
|
||||
final app = adapter.findWhereIdInLocal({uri.host}).firstOrNull;
|
||||
if (app != null) {
|
||||
appRouter.go('/details', extra: app);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:zapstore/main.dart';
|
||||
import 'package:zapstore/main.data.dart';
|
||||
import 'package:zapstore/models/app.dart';
|
||||
import 'package:zapstore/utils/system_info.dart';
|
||||
import 'package:zapstore/widgets/app_drawer.dart';
|
||||
|
||||
@@ -23,7 +25,7 @@ class DrawerContainer extends StatelessWidget {
|
||||
final state = ref.watch(systemInfoProvider);
|
||||
return switch (state) {
|
||||
AsyncData(:final value) => Text(
|
||||
'Version: ${value.zsInfo.versionName} (${value.zsInfo.versionCode}, $kDbVersion)',
|
||||
'Version: ${value.zsInfo.versionName} (${value.zsInfo.versionCode}, $kDbVersion) -- ${ref.apps.appAdapter.queriedAtMap.length}',
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
_ => Container(),
|
||||
|
||||
Reference in New Issue
Block a user