Skip to content

Commit

Permalink
optimize model loading in /admin/upgrade-versions
Browse files Browse the repository at this point in the history
  • Loading branch information
berekuk committed Jun 14, 2024
1 parent 1d14952 commit f1c15f0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ModelList: FC<{
id
slug
}
...UpgradeableModel
...UpgradeableModel_Ref
}
`,
modelsRef
Expand Down
58 changes: 43 additions & 15 deletions packages/hub/src/app/admin/upgrade-versions/UpgradeableModel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";
import { FC, use } from "react";
import { useFragment } from "react-relay";
import { useFragment, useLazyLoadQuery } from "react-relay";
import { graphql } from "relay-runtime";

import {
Expand All @@ -11,34 +11,62 @@ import {
} from "@quri/versioned-squiggle-components";

import { EditSquiggleSnippetModel } from "@/app/models/[owner]/[slug]/EditSquiggleSnippetModel";
import { extractFromGraphqlErrorUnion } from "@/lib/graphqlHelpers";
import { squiggleHubLinker } from "@/squiggle/components/linker";

import { UpgradeableModel$key } from "@/__generated__/UpgradeableModel.graphql";
import { UpgradeableModel_Ref$key } from "@/__generated__/UpgradeableModel_Ref.graphql";
import { UpgradeableModelQuery } from "@/__generated__/UpgradeableModelQuery.graphql";

export const UpgradeableModel: FC<{
modelRef: UpgradeableModel$key;
modelRef: UpgradeableModel_Ref$key;
}> = ({ modelRef }) => {
const model = useFragment(
const incompleteModel = useFragment(
graphql`
fragment UpgradeableModel on Model {
fragment UpgradeableModel_Ref on Model {
id
currentRevision {
content {
__typename
... on SquiggleSnippet {
id
code
version
seed
slug
owner {
id
slug
}
}
`,
modelRef
);

const result = useLazyLoadQuery<UpgradeableModelQuery>(
graphql`
query UpgradeableModelQuery($input: QueryModelInput!) {
model(input: $input) {
__typename
... on Model {
id
currentRevision {
content {
__typename
... on SquiggleSnippet {
id
code
version
seed
}
}
}
...EditSquiggleSnippetModel
}
}
...EditSquiggleSnippetModel
}
`,
modelRef
{
input: {
slug: incompleteModel.slug,
owner: incompleteModel.owner.slug,
},
}
);

const model = extractFromGraphqlErrorUnion(result.model, "Model");

const currentRevision = model.currentRevision;

if (currentRevision.content.__typename !== "SquiggleSnippet") {
Expand Down

0 comments on commit f1c15f0

Please sign in to comment.