Firestore - 意外读取 [英] Firestore - unexpected reads

查看:26
本文介绍了Firestore - 意外读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我确实有一个有趣的问题,如果你们中的任何人能够帮助我,我会很高兴.

there guys, I do have an interesting problem here and I would be really glad if any of you it will be able to help me with that.

我的应用流程是什么:

  1. 使用电子邮件、密码和其他一些详细信息注册:
  2. 用户 firebase 以对用户进行身份验证并通过电子邮件和密码创建帐户,同时我将用户的自定义数据写入数据库.
  3. 登录用户.

就是这样,这就是我所有的基本逻辑,据我所知,你怎么看我没有从数据库中读取任何数据.

That's it, that's all my basic logic, and how you can see I'm not doing any reading from the DB so far as I know.

现在...问题是,由于一些奇怪的原因,当我注册我的用户时,我要去 firebase 控制台查看我的数据库的使用情况,我会看到类似...对于一个用户创建后,我将有 1 次写入(正如我预期的那样很好),但还有 13-20 次从 DB 读取.

Now... the problem is that from some weird reason when I'm registering my user I'm going to the firebase console to see the usage of my DB and I will see something like... for one user which was created I will have 1 write (which is fine as I was expected) but also 13-20 READS FROM DB.

现在这就是我的问题,为什么在我只进行身份验证和写入时我会阅读关于 firestorm 的内容?

Now that's my question, WHY on earth I have reads on firestorm when I'm doing just auth and writes?

这是我现在正在使用的数据库代码.

Here it's my DB code which I'm using right now.

class DatabaseFirebase implements BaseDataBase {
  final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
  final FirebaseStorage _storage = FirebaseStorage.instance;

  FirebaseUser _firebaseUser;
  Firestore _firestore = Firestore.instance;

  @override
  Future<String> login(String email, String password) async {
    _firebaseUser = await _firebaseAuth.signInWithEmailAndPassword(
        email: email, password: password);
    return _firebaseUser.uid;
  }

  @override
  Future<String> register(String email, String password) async {
    _firebaseUser = await _firebaseAuth.createUserWithEmailAndPassword(
        email: email, password: password);
    return _firebaseUser.uid;
  }

  @override
  Future<UserData> getCurrentUser() async {
    if (_firebaseUser == null)
      _firebaseUser = await _firebaseAuth.currentUser();
    UserData user = UserData();
    user.email = _firebaseUser?.email;
    user.name = _firebaseUser?.displayName;
    return user;
  }

  @override
  Future<void> logout() async {
    _firebaseAuth.signOut();
  }

  @override
  Future<void> onAuthStateChanged(void Function(FirebaseUser) callback) async {
    _firebaseAuth.onAuthStateChanged.listen(callback);
  }

  @override
  Future<void> writeUser(UserData user) async {
    _firestore.collection("Users").add(user.toMap()).catchError((error) {
      print(error);
    });
  }
}

如果你们中的一些人知道,你能向我解释我需要在哪里/如何搜索才能找到这个错误吗?因为你怎么看我从来没有使用任何阅读.

If some of you know could you explain to me where/how I need to search in order to find this bug? Because how you can see I'm not using any read what so ever.

推荐答案

鉴于我们不了解所有可能的数据库访问路径,因此无法确定,但您应该知道 Firebase 控制台的使用会导致读取.如果您将控制台在具有繁忙写入活动的集合/文档上保持打开状态,控制台将自动读取更新控制台显示的更改.这通常是意外读取的来源.

It's impossible to know for sure given that we don't understand all possible routes of access into your database, but you should be aware that use of the Firebase console will incur reads. If you leave the console open on a collection/document with busy write activity, the console will automatically read the changes that update the console's display. This is very often the source of unexpected reads.

如果没有您正在采取的所有步骤的完整复制步骤,就无法确定.

Without full reproduction steps of exactly all the steps you're taking, there's no way to know for sure.

Firebase 目前不提供跟踪文档读取来源的工具.如果您需要衡量应用中的特定读取,则必须以某种方式自己跟踪.

Firebase currently does not provide tools to track the origin of document reads. If you need to measure specific reads from your app, you will have to track that yourself somehow.

这篇关于Firestore - 意外读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆