Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realtime Database: Database listener clears children when performing another query in same ref #14137

Open
diegogarciar opened this issue Nov 18, 2024 · 3 comments

Comments

@diegogarciar
Copy link

Description

For a chat application I am doing a double query, I have a listener for new messages, and a paginated query for old messages.

I just discovered that my listener is impacted by the queries I do on that same path, which I believe shouldn't be the case

Reproducing the issue

  final database = FirebaseDatabase.instance;

  final path = '/test_path';
  String? randomKey;
  for (var i = 0; i < 10; i++) {
    final ref = database.ref(path).push();
    if (i == 5) {
      randomKey = ref.key;
    }
    await ref.set('test $i');
  }

  final ref = database.ref(path);
  var hasQueried = false;
  ref.orderByKey().startAt(randomKey).onValue.listen((event) {
    print('listener  ${event.snapshot.children.length}');

    if (!hasQueried) {
      hasQueried = true;
      ref.orderByKey().limitToLast(3).endBefore(randomKey).get().then((data) {
        print('obtained previous messages ${data.children.length}');
      });
    }
  });

Firebase SDK Version

11.2

Xcode Version

16.1

Installation Method

CocoaPods

Firebase Product(s)

Database

Targeted Platforms

iOS

Relevant Log Output

listener  5
obtained previous messages 3
listener  0

If using Swift Package Manager, the project's Package.resolved

Expand Package.resolved snippet
Replace this line with the contents of your Package.resolved.

If using CocoaPods, the project's Podfile.lock

Expand Podfile.lock snippet
Replace this line with the contents of your Podfile.lock!
@google-oss-bot
Copy link

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@diegogarciar
Copy link
Author

The issue was first reported here firebase/flutterfire#13822, will submit the Podfile.lock shortly!

@paulb777
Copy link
Member

May be related to long-standing #12168

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants