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

🐛 [firebase_ui_firestore] FirestoreDataTable need polishing to only query the right amount of data #11

Open
wer-mathurin opened this issue Jun 27, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request firestore

Comments

@wer-mathurin
Copy link

Bug report

Describe the bug
After the code(bellow) the first item is more an discussion than a bub, but the point 2 and 3 seems to be bugs.

@override
  Widget build(BuildContext context) {
    return StreamBuilder(
      stream: _query.snapshots(),
      builder: (context, snapshot) {
        return AggregateQueryBuilder(
          query: _query.count(),
          builder: (context, aggSsnapshot) {
            return FirestoreQueryBuilder<Map<String, Object?>>(
              query: _query,
              builder: (context, snapshot, child) {
                if (aggSsnapshot.hasData) {
                  source.setFromSnapshot(snapshot, aggSsnapshot.requireData);
                } else {
                  source.setFromSnapshot(snapshot);
                }

                return AnimatedBuilder(
                  animation: source,
                  builder: (context, child) {
                    final actions = [
                      ...?widget.actions,
                      if (widget.canDeleteItems &&
                          source._selectedRowIds.isNotEmpty)
                        IconButton(
                          icon: const Icon(Icons.delete),
                          onPressed: source.onDeleteSelectedItems,
                        ),
                    ];
                    return PaginatedDataTable(
                      source: source,
                      onSelectAll: selectionEnabled ? source.onSelectAll : null,
                      onPageChanged: widget.onPageChanged,
                      showCheckboxColumn: widget.showCheckboxColumn,
                      arrowHeadColor: widget.arrowHeadColor,
                      checkboxHorizontalMargin: widget.checkboxHorizontalMargin,
                      columnSpacing: widget.columnSpacing,
                      dataRowMaxHeight: widget.dataRowMaxHeight,
                      dataRowMinHeight: widget.dataRowMinHeight,
                      dragStartBehavior: widget.dragStartBehavior,
                      headingRowHeight: widget.headingRowHeight,
                      horizontalMargin: widget.horizontalMargin,
                      rowsPerPage: widget.rowsPerPage,
                      showFirstLastButtons: widget.showFirstLastButtons,
                      sortAscending: widget.sortAscending,
                      sortColumnIndex: widget.sortColumnIndex,
                      header: actions.isEmpty
                          ? null
                          : (widget.header ?? const SizedBox()),
                      actions: actions.isEmpty ? null : actions,
                      columns: [
                        for (final head in widget.columnLabels.values)
                          DataColumn(label: head)
                      ],
                    );
                  },
                );
              },
            );
          },
        );
      },
    );
  }

Couple os things:

  1. Do we really want StreamBuilder at the first place?
    Seems it only needed to make sure the AggregateQueryBuilder will return the right number of rows, if the data is changing on the query side....but this defeat the intent of limiting the data retrieved, we even make an extra query when we can use the docs.lenght to update the PaginatedDataTable bottom navigation information.

  2. I think the we need to pass to the FirestoreQueryBuilder to limit the snapshot to the number of rows we have in the page => pageSize: widget.rowsPerPage, otherwise if you allow the checkbox and select all items on the page (with let say 10 rows) you will get 20 item selected !!!

  3. With the addition of the _aggregateSnapshot I think the override of : bool get isRowCountApproximate => _aggregateSnapshot?.count == null || (_previousSnapshot!.isFetching || _previousSnapshot!.hasMore);

maybe not right, because the intent of having AggregateQueryBuilder seems to have the exact number of rows, so the isRowCountApproximate can be always false. But we can argue the query can send more rows the next time tap on the next page...

@darshankawar
Copy link

Thanks for the report. Treating this as an enhancement.

@lesnitsky lesnitsky transferred this issue from firebase/flutterfire Aug 18, 2023
@lesnitsky lesnitsky added firestore enhancement New feature or request labels Aug 18, 2023
Copy link

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

@github-actions github-actions bot added the Stale Issue with no recent activity label Nov 12, 2024
@russellwheatley russellwheatley removed the Stale Issue with no recent activity label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request firestore
Projects
None yet
Development

No branches or pull requests

5 participants