claude refactor

This commit is contained in:
2026-05-04 13:54:39 +02:00
parent 9973f12733
commit 551c1bf1fa
125 changed files with 4484 additions and 2544 deletions
+11 -12
View File
@@ -13,8 +13,8 @@ abstract class RequestCache<T extends ApiResponse?> {
static String collection = 'MarianumMobile';
int maxCacheTime;
Function(T) onUpdate;
Function(Exception) onError;
void Function(T)? onUpdate;
void Function(Exception) onError;
bool? renew;
RequestCache(this.maxCacheTime, this.onUpdate, {this.onError = ignore, this.renew = false});
@@ -22,24 +22,23 @@ abstract class RequestCache<T extends ApiResponse?> {
static void ignore(Exception e) {}
Future<void> start(String document) async {
var tableData = await Localstore.instance.collection(collection).doc(document).get();
if(tableData != null) {
onUpdate(onLocalData(tableData['json']));
final tableData = await Localstore.instance.collection(collection).doc(document).get();
if (tableData != null) {
onUpdate?.call(onLocalData(tableData['json']));
}
if(DateTime.now().millisecondsSinceEpoch - (maxCacheTime * 1000) < (tableData?['lastupdate'] ?? 0)) {
if(renew == null || !renew!) return;
if (DateTime.now().millisecondsSinceEpoch - (maxCacheTime * 1000) < (tableData?['lastupdate'] ?? 0)) {
if (renew == null || !renew!) return;
}
try {
var newValue = await onLoad();
onUpdate(newValue);
final newValue = await onLoad();
onUpdate?.call(newValue);
Localstore.instance.collection(collection).doc(document).set({
'json': jsonEncode(newValue),
'lastupdate': DateTime.now().millisecondsSinceEpoch
'lastupdate': DateTime.now().millisecondsSinceEpoch,
});
} on Exception catch(e) {
} on Exception catch (e) {
onError(e);
}
}