Commit 0e17f906 authored by Amirjanyan's avatar Amirjanyan
Browse files

small refactoring

parent a724230a
Pipeline #5326 passed with stages
in 5 minutes and 20 seconds
Showing with 8 additions and 23 deletions
+8 -23
......@@ -191,13 +191,4 @@ class ItemEdgeRecord {
print("ERROR: Could not locate edge for synced edge: $syncedEdge");
}
}
static ItemEdgeRecord? fromSyncEdgeDict(
{required Map<String, dynamic> dict, required DatabaseController dbController}) {
if (dict["source"] != null && dict["target"] != null && dict["name"] != null) {
return ItemEdgeRecord.fromSyncDict(dict);
} else {
print("ERROR: Source, target or name is missing for edge");
}
}
}
......@@ -539,12 +539,11 @@ class ItemRecord with EquatableMixin {
var itemList =
(await ItemRecord.fetchWithUIDs(uidList, dbController)).toMapByKey((item) => item.uid);
var dictList = responseObjects.compactMap<Map<String, dynamic>>((dict) {
if (dict is! Map<String, dynamic>) return null;
if (dict is! Map<String, dynamic> || dict["id"] == null) return null;
dict["rowId"] = itemList[dict["id"]]?.rowId;
return dict;
});
await Future.forEach<Map<String, dynamic>>(dictList, (dict) async {
if (dict["id"] == null) return;
// If the item has file and it does not exist on disk, mark the file to be downloaded
if (dict["type"] == "File" && dict["_item"] == null && dict.containsKey("sha256")) {
String? fileName = dict["sha256"];
......@@ -608,31 +607,26 @@ class ItemRecord with EquatableMixin {
edges.forEach((edge) {
edgeItems.addAll([edge["_item"], edge]);
});
List<ItemEdgeRecord> edgeRecords = [];
var groupedEdgeItems = edgeItems.toMapByKey((item) => item["id"] as String);
var uidList = edgeItems.map((item) => item["id"] as String).toList();
var groupedEdgeItemRecords =
(await ItemRecord.fetchWithUIDs(groupedEdgeItems.keys.toList(), dbController))
.toMapByKey((item) => item.uid);
edges.forEach((edge) {
(await ItemRecord.fetchWithUIDs(uidList, dbController)).toMapByKey((item) => item.uid);
return edges.map((edge) {
ItemRecord self = groupedEdgeItemRecords[edge["id"]]!;
ItemRecord target = groupedEdgeItemRecords[edge["_item"]["id"]]!;
ItemRecord source = edge["source"];
var edgeDict = {
"self": edge["id"],
"self": self.uid,
"source": source.uid,
"name": edge["_edge"],
"target": edge["_item"]["id"],
"target": target.uid,
"selfRowId": self.rowId,
"targetRowId": target.rowId,
"sourceRowId": source.rowId
};
var edgeRecord = ItemEdgeRecord.fromSyncEdgeDict(dict: edgeDict, dbController: dbController);
if (edgeRecord != null) edgeRecords.add(edgeRecord);
});
return edgeRecords;
return ItemEdgeRecord.fromSyncDict(edgeDict);
}).toList();
}
static List<ItemPropertyRecord> propertiesFromSyncItemDict(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment