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

Use estimated dataset count for index page query #4114

Merged
merged 4 commits into from Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions app/packages/app/src/pages/IndexPage.tsx
@@ -1,11 +1,10 @@
import { Snackbar } from "@fiftyone/core";
import { Snackbar, Starter } from "@fiftyone/core";
import React from "react";
import { usePreloadedQuery } from "react-relay";
import { graphql } from "relay-runtime";
import Nav from "../components/Nav";
import { Route } from "../routing";
import { IndexPageQuery } from "./__generated__/IndexPageQuery.graphql";
import { Starter } from "@fiftyone/core";

const IndexPageQueryNode = graphql`
query IndexPageQuery($search: String = "", $count: Int, $cursor: String) {
Expand All @@ -16,17 +15,15 @@ const IndexPageQueryNode = graphql`
multicolorKeypoints
showSkeletons
}
allDatasets: datasets(search: "") {
total
}
allDatasets: estimatedDatasetCount
...NavFragment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we also need to update line 29 of this file? Or will it work as is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the field is still aliased as allDatasets, I think it should work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, total is missing now 👍

...configFragment
}
`;

const IndexPage: Route<IndexPageQuery> = ({ prepared }) => {
const queryRef = usePreloadedQuery(IndexPageQueryNode, prepared);
const totalDatasets = queryRef?.allDatasets?.total;
const totalDatasets = queryRef.allDatasets;

return (
<>
Expand Down
52 changes: 19 additions & 33 deletions app/packages/app/src/pages/__generated__/IndexPageQuery.graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/schema.graphql
Expand Up @@ -599,6 +599,7 @@ type Query {
context: String!
dev: Boolean!
doNotTrack: Boolean!
estimatedDatasetCount: Int!
samples(
dataset: String!
view: BSONArray!
Expand Down
4 changes: 4 additions & 0 deletions fiftyone/server/query.py
Expand Up @@ -411,6 +411,10 @@ def dev(self) -> bool:
def do_not_track(self) -> bool:
return fo.config.do_not_track

@gql.field
async def estimated_dataset_count(self, info: Info = None) -> int:
return await info.context.db.datasets.estimated_document_count()

dataset: Dataset = gql.field(resolver=Dataset.resolver)
datasets: Connection[Dataset, str] = gql.field(
resolver=get_paginator_resolver(
Expand Down