我正在写 Flutter + Firestore,有一项任务是从数据库中获取每种汽车维修类型的操作列表。也就是说,我首先获取所有类型的 TO 的列表,然后通过每个类型的 ID 在一个循环中转到 firestore 并获取操作列表。
速度问题,对于7种维护的列表,大约需要3-5秒,这对于用户来说是无法接受的。
这是我的功能代码:
class DashboardService {
DataService dataService = DataService();
getMarkers(List<Entry> entries, String carId) async {
var _marker = []; // коллекция списков операций для каждого регламента ТО
// Получаю списки операций для регламентов ТО
for (int i = 0; i < entries.length; i++) {
List<Operation> _operations = [];
_operations =
await dataService.getEntryOperations(entries[i].entryId, carId);
_marker.add({'entry': entries[i], 'operations': _operations});
}
return _marker;
}
}
添加这样组织的信息:
fs
.document(docId)
.collection('cars')
.document(carId)
.collection('entries')
.document(entryId)
.collection('operations')
.document(operationRef.documentID)
.setData(operationData);
如何优化和加速这个操作的执行?也许您需要更改信息存储的结构?
在其中一个电报频道中,他们提出了一个解决方案,很好地将等待时间减少到大约 1-2 秒