android - Firestore 写入数据有时会丢失
问题描述
我们将 Firebase Firestore 与我们简单的杂货配送应用程序 (android) 一起使用一年多。它超级快而且很棒,但它在写入时总是丢失数据。
之前,不使用transactions
and batched writes
,问题更加持久(大约 10/1000 个条目)。使用后问题有所减少但并未完全消失(约 2/1000 个条目)。
场景:
我们很少有集合在添加产品时设置/更新,即products
,stock
和daylogs
. 当我们添加/更新产品时,事务会将不同的数据写入所有这些集合。但有时(2/1000),事务成功并写入products
和stock
但不是daylogs
。
这是代码的更简单版本。虽然,我认为这不是代码问题,因为它在 99% 的时间都可以正常工作。
firebasefirestore.runTransaction(new Transaction.Function<String>() {
@Override
public String apply(@NonNull Transaction transaction) throws FirebaseFirestoreException {
DocumentReference thisProduct = rootRef.collection("products").document(docId);
DocumentReference thisStock = rootRef.collection("stock").document(docId);
DocumentReference logs = rootRef.collection("daylogs").document(LogDocumentId);
transaction.update(thisProduct, data);
transaction.update(thisStock, data);
transaction.update(logs, data);
String complete = "1";
return complete;
}
}).addOnSuccessListener(new OnSuccessListener<String>() {
@Override
public void onSuccess(String result) {
if (result.equals("1")) {
Toast.makeText(AddProduct.this, "Data Added", Toast.LENGTH_SHORT).show();
}
}
});
为什么会这样?如何解决这个问题?
对不起我的英语不好。请帮忙。
解决方案
推荐阅读
- c++ - 如何使用 Visual Studio 2019 和 c++ 链接 OpenSSL 库?
- android - 我可以在 Google Play 控制台中以与之前上传的名称相同的名称上传应用程序吗?
- matlab - 如何将向量传递给相同大小的函数句柄,以便它自动将第一个输入作为第一个变量等等?MATLAB
- python - 为用 vanilla Python 编写的 API 自动生成 Swagger 文档
- reactjs - 缺少 Django、React 和 Rest Framework JWT 身份验证标头
- css - 在类名中使用 `sass` 到 `@import` 或 `@use` css 文件,并带有 `cra 4`
- linux - Amazon S3 通过保留目录结构将文件从 S3 文件夹移动到 Ec2 文件夹
- java - E/unknown:ReactNative: 本地调用异常
- javascript - 如何在 MERN 中生成自动序列号?
- c# - 如何做一个