Skip to content

FR: ability to *only* subscribe to doc/collection changes #1551

@jorroll

Description

@jorroll

At the moment, there doesn't appear to be a way to only subscribe to the changes of a collection or document without also immediately downloading the entire current collection / the document. E.g. if you already have the latest version of a document downloaded, you might want to just subscribe to changes to that document without re-downloading the current version of the document.

At the moment, methods like QuerySnapshot#docChanges retrieve the entire query, without any apparent way of just getting changes (i.e. on initial subscription, nothing should be returned).

This is a highly desirable feature request from a performance / data consumption standpoint. My goal is to only load documents once, and subsequently load them from the cache while ensuring changes are watched.

Usage might be the following:

  • Component calls a personService to retrieve all 'people' where person.age > 18.
  • personService checks to see if this query has been run before. If it has not, it uses the firebase-js-sdk to fetch all documents from the 'people' collection where person.age > 18 and it stores these documents in an ngrx/redux store. It returns these documents to the caller.
  • On subsequent invocations, personService sees that the query was run before, and just runs the query against the local ngrx/redux store.
  • In order to ensure that already downloaded documents / queries are up to date, on first invocation the personService also seperately subscribes to all changes to the 'people' collection (no where filter). This subscription is now maintained for the lifetime of the application. As these changes come in, the personService updates, adds, or removes items from the store as appropriate. This ensures that the client only need to issue a particular query to the backend once, and subsequently can just query data locally. This has major performance implications.

Unfortunately, there does not appear to be any way to accomplish this scenario at the moment because when you subscribe to all changes to the 'people' collection (no where filter), the entire people collection will be returned, which may have thousands of documents.

[REQUIRED] Describe your environment

  • Operating System version: Mac OS 10.14
  • Browser version: Google Chrome 70
  • Firebase SDK version: 5.5.5
  • Firebase Product: Firebase

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions