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

De-Duplicate API calls in DLP #1208

Merged
merged 6 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions web/src/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Asset, Dandiset, Paginated, User, Version, Info, AssetFile, AssetFolder,
} from '@/types';
import { Dandiset as DandisetMetadata, DandisetContributors, Organization } from '@/types/schema';
import store from '@/store';

if (!process.env.VUE_APP_DANDI_API_ROOT) {
throw new Error('Environment variable "VUE_APP_DANDI_API_ROOT" must be set.');
Expand Down Expand Up @@ -161,8 +162,7 @@ const dandiRest = new Vue({
}
},
async mostRecentVersion(identifier: string) {
// TODO: find a way to do this with fewer requests
const count = (await this.versions(identifier))?.count;
const count = store.state.dandiset.versionCount; // todo - this.$store.state is undefined?
DeepikaGhodki marked this conversation as resolved.
Show resolved Hide resolved
if (!count) {
return null;
}
Expand Down
14 changes: 11 additions & 3 deletions web/src/store/dandiset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface DandisetState {
loading: boolean,
owners: User[]|null,
schema: any,
versionCount: Number,
}

const dandisetGetterContext = (
Expand All @@ -30,6 +31,7 @@ const dandisetModule = defineModule({
loading: false, // No mutation, as we don't want this mutated by the user
owners: null,
schema: null,
versionCount: 0,
} as DandisetState,
getters: {
version(...args): string {
Expand Down Expand Up @@ -75,6 +77,9 @@ const dandisetModule = defineModule({
setLoading(state: DandisetState, loading: boolean) {
state.loading = loading;
},
setVersionCount(state: DandisetState, versionCount: Number) {
state.versionCount = versionCount;
},
},
actions: {
async uninitializeDandisets(context: any) {
Expand All @@ -84,24 +89,27 @@ const dandisetModule = defineModule({
commit.setVersions(null);
commit.setOwners(null);
commit.setLoading(false);
commit.setVersionCount(0);
},
async initializeDandisets(context: any, { identifier, version }) {
const { dispatch } = dandisetActionContext(context);
await dispatch.uninitializeDandisets();

// this can be done concurrently, don't await
dispatch.fetchDandisetVersions({ identifier });
// first fetch all versions, set total count
// use count to fetch latest dandiset, must be sequential
await dispatch.fetchDandisetVersions({ identifier });
await dispatch.fetchDandiset({ identifier, version });
await dispatch.fetchOwners(identifier);
DeepikaGhodki marked this conversation as resolved.
Show resolved Hide resolved
},
// fetch versions and total version count
async fetchDandisetVersions(context: any, { identifier }) {
const { commit } = dandisetActionContext(context);
commit.setLoading(true);

const res = await dandiRest.versions(identifier);
if (res) {
const { results } = res;
commit.setVersions(results || []);
commit.setVersionCount(res.count);
}

commit.setLoading(false);
Expand Down
2 changes: 1 addition & 1 deletion web/src/views/DandisetLandingView/DandisetLandingView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default defineComponent({
}
}, { immediate: true });

watchEffect(async () => {
watch([() => props.version, () => props.identifier], async () => {
const { identifier, version } = props;
if (version) {
// On version change, fetch the new dandiset (not initial)
Expand Down