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

Batch asset invalidations #11937

Open
wants to merge 91 commits into
base: develop
Choose a base branch
from
Open

Conversation

somebody1234
Copy link
Contributor

@somebody1234 somebody1234 commented Dec 24, 2024

Pull Request Description

  • Close https://github.com/enso-org/cloud-v2/issues/1627
    • Batch asset invalidations for:
      • Bulk deletes
      • Bulk undo deletes (restores)
      • Bulk copy/move
      • Bulk download
      • This avoids flickering when the directory list is invalidated multiple times (once for the mutation corresponding to each asset)

Codebase changes:

  • Remove all AssetEvents and AssetListEvents. Remaining events have been moved to TanStack Query mutations in this PR, as it is neccessary for batch invalidation functionality.
  • Remove key and directoryKey from AssetTreeNode, and keys in general in favor of ids. Not strictly necessary, but it was causing logic issues and is (IMO) a nice simplification to be able to do.

Important Notes

None

Testing instructions

  • Ideally test all asset list interactions, especially ones that fire mutations:
    • Copy, delete, undelete
    • Create assets (optional)
    • Add labels (via drag)
    • Download

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • ~~Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.~
  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • Unit tests have been written where possible.
  • If meaningful changes were made to logic or tests affecting Enso Cloud integration in the libraries,
    or the Snowflake database integration, a run of the Extra Tests has been scheduled.
    • If applicable, it is suggested to paste a link to a successful run of the Extra Tests.

@somebody1234
Copy link
Contributor Author

Can we invalidate the all listDirectories queries when we restore from the trash folder?

weird, we should already be doing this, right?

@somebody1234
Copy link
Contributor Author

each asset get rerendered on each refetch

would you happen to know how we managed to avoid that previously?

@somebody1234
Copy link
Contributor Author

somebody1234 commented Dec 30, 2024

anyway @MrFlashAccount ready for re-review i guess. lmk if there are specific things i should split out

return result
}
}, [listUserGroupsQuery.data, listUsersQuery.data])
const listUserGroupsQuery = useBackendQuery(backend, 'listUserGroups', EMPTY_ARRAY)
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, using queries like this should be discouraged as it throws away the state of the query - loading, fetching, error, etc. instead, we should fetch on components level and if we want to hide some logic behind an abstraction - introduce a hook/function that accepts data as parameters

Copy link
Contributor

@MrFlashAccount MrFlashAccount left a comment

Choose a reason for hiding this comment

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

Still not final yet, tired of reading changes like [] -> EMPTY_ARRAY

app/gui/src/dashboard/hooks/backendHooks.tsx Outdated Show resolved Hide resolved
type RestoreAssetsMutation = Mutation<null, Error, readonly AssetId[]>

/** Return matching in-flight "restore assets" mutations. */
export function useRestoreAssetsMutationState<Result>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's better to call it useIsRestoring... ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it returns the mutation object, not a boolean, so i'm not sure whether that name makes sense

app/gui/src/dashboard/hooks/backendHooks.tsx Outdated Show resolved Hide resolved
}

/** Clear the trash folder. */
export function useClearTrashMutation(backend: Backend) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can unify this hook with removing a group of items, a single item, by passing the ids into mutation params?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how's that different to the current code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think this has the same "wrap mutation into a mutation" issue btw - but i'm not sure how to fix it because we potentially need to do a fetch for this one

}

/** Duplicate a specific version of a project. */
export function useDuplicateProjectMutation(backend: Backend) {
Copy link
Contributor

@MrFlashAccount MrFlashAccount Dec 30, 2024

Choose a reason for hiding this comment

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

Please ask Pawel if we need to specify a name for duplicating assest (now we don't need to pass a name when we create them), but this makes sense for the LocalBackend.

}

/** Call "add label" mutations for a list of assets. */
export function addAssetsLabelsMutationOptions(backend: Backend) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes me wondering, why somewhere we use useMutation, in other places we use mutationOptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ideally everything should be mutationOptions imo, but some of them need to use hooks so that is not possible as is

app/gui/src/dashboard/hooks/backendHooks.tsx Outdated Show resolved Hide resolved
app/gui/src/dashboard/layouts/Settings/MembersTable.tsx Outdated Show resolved Hide resolved
@somebody1234 somebody1234 force-pushed the wip/sb/batch-invalidations branch from b0a3b11 to a1d8517 Compare January 3, 2025 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. g-dashboard x-refactor Changes that should not be visible to the end-user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants