refactored sync repo
This commit is contained in:
@@ -45,9 +45,8 @@ class BangSyncRepository extends _$BangSyncRepository {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Result<void>> _syncBangGroup(
|
Future<Result<void>> syncBangGroup(
|
||||||
BangGroup group,
|
BangGroup group,
|
||||||
Uri url,
|
|
||||||
Duration? syncInterval,
|
Duration? syncInterval,
|
||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
@@ -59,7 +58,7 @@ class BangSyncRepository extends _$BangSyncRepository {
|
|||||||
final result = await _fetchAndSync(
|
final result = await _fetchAndSync(
|
||||||
sourceService: ref.read(bangSourceServiceProvider.notifier),
|
sourceService: ref.read(bangSourceServiceProvider.notifier),
|
||||||
db: db,
|
db: db,
|
||||||
url: url,
|
url: Uri.parse(group.url),
|
||||||
group: group,
|
group: group,
|
||||||
syncInterval: syncInterval,
|
syncInterval: syncInterval,
|
||||||
);
|
);
|
||||||
@@ -84,40 +83,20 @@ class BangSyncRepository extends _$BangSyncRepository {
|
|||||||
return _db.syncDao.lastSyncOfGroup(group).watchSingleOrNull();
|
return _db.syncDao.lastSyncOfGroup(group).watchSingleOrNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Result<void>> syncGeneralBangs({Duration? syncInterval}) =>
|
Future<Map<BangGroup, Result<void>>> syncBangGroups({
|
||||||
_syncBangGroup(
|
Set<BangGroup>? groups,
|
||||||
BangGroup.general,
|
|
||||||
Uri.parse(BangGroup.general.url),
|
|
||||||
syncInterval,
|
|
||||||
);
|
|
||||||
|
|
||||||
Future<Result<void>> syncKagiBangs({Duration? syncInterval}) =>
|
|
||||||
_syncBangGroup(
|
|
||||||
BangGroup.kagi,
|
|
||||||
Uri.parse(BangGroup.kagi.url),
|
|
||||||
syncInterval,
|
|
||||||
);
|
|
||||||
|
|
||||||
Future<Result<void>> syncAssistantBangs({Duration? syncInterval}) =>
|
|
||||||
_syncBangGroup(
|
|
||||||
BangGroup.assistant,
|
|
||||||
Uri.parse(BangGroup.assistant.url),
|
|
||||||
syncInterval,
|
|
||||||
);
|
|
||||||
|
|
||||||
Future<Map<BangGroup, Result<void>>> syncAllBangGroups({
|
|
||||||
Duration? syncInterval,
|
Duration? syncInterval,
|
||||||
}) async {
|
}) async {
|
||||||
//Run isolated operations
|
//Default to all sources
|
||||||
final generalSync = syncGeneralBangs(syncInterval: syncInterval);
|
groups ??= BangGroup.values.toSet();
|
||||||
final assistantSync = syncAssistantBangs(syncInterval: syncInterval);
|
|
||||||
final kagiSync = syncKagiBangs(syncInterval: syncInterval);
|
|
||||||
|
|
||||||
return {
|
//Run isolated operations
|
||||||
BangGroup.general: await generalSync,
|
final futures = groups.map(
|
||||||
BangGroup.assistant: await assistantSync,
|
(source) => syncBangGroup(source, syncInterval)
|
||||||
BangGroup.kagi: await kagiSync,
|
.then((result) => MapEntry(source, result)),
|
||||||
};
|
);
|
||||||
|
|
||||||
|
return Map.fromEntries(await Future.wait(futures));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ part of 'sync.dart';
|
|||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
||||||
String _$bangSyncRepositoryHash() =>
|
String _$bangSyncRepositoryHash() =>
|
||||||
r'865164c809e2f171a6b748d149780383d6e3483f';
|
r'1e6341c8daf25aaee61d158f94445564d4450a9e';
|
||||||
|
|
||||||
/// See also [BangSyncRepository].
|
/// See also [BangSyncRepository].
|
||||||
@ProviderFor(BangSyncRepository)
|
@ProviderFor(BangSyncRepository)
|
||||||
|
|||||||
Reference in New Issue
Block a user