Skip to content

Commit

Permalink
feat(dcellar-web-ui): fix query quota slow
Browse files Browse the repository at this point in the history
  • Loading branch information
aiden-cao committed Sep 15, 2023
1 parent b84d58d commit d59f222
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 45 deletions.
2 changes: 2 additions & 0 deletions apps/dcellar-web-ui/src/facade/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ export const getUserBuckets = async (

export const getBucketReadQuota = async ({
bucketName,
endpoint,
seedString,
address,
}: TGetReadQuotaParams): Promise<ErrorResponse | [IQuotaProps, null]> => {
const client = await getClient();
const payload: ReadQuotaRequest = {
bucketName,
endpoint,
};
const [res, error] = await client.bucket
.getBucketReadQuota(payload, {
Expand Down
2 changes: 2 additions & 0 deletions apps/dcellar-web-ui/src/facade/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const getObjectInfoAndBucketQuota = async ({
objectName,
address,
seedString,
endpoint,
}: {
bucketName: string;
objectName: string;
Expand All @@ -26,6 +27,7 @@ export const getObjectInfoAndBucketQuota = async ({
.getBucketReadQuota(
{
bucketName,
endpoint,
},
{
type: 'EDDSA',
Expand Down
24 changes: 10 additions & 14 deletions apps/dcellar-web-ui/src/facade/virtual-group.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { getClient } from "@/base/client";
import { getClient } from '@/base/client';
import {
QueryGlobalVirtualGroupFamilyRequest,
QueryGlobalVirtualGroupFamilyResponse
} from "@bnb-chain/greenfield-cosmos-types/greenfield/virtualgroup/query";
import { resolve } from "./common";
import { ErrorResponse, commonFault } from "./error";
QueryGlobalVirtualGroupFamilyResponse,
} from '@bnb-chain/greenfield-cosmos-types/greenfield/virtualgroup/query';
import { resolve } from './common';
import { ErrorResponse, commonFault } from './error';

export const getVirtualGroupFamily = async (params: QueryGlobalVirtualGroupFamilyRequest): Promise<ErrorResponse | [QueryGlobalVirtualGroupFamilyResponse, null]> => {
export const getVirtualGroupFamily = async (
params: QueryGlobalVirtualGroupFamilyRequest,
): Promise<ErrorResponse | [QueryGlobalVirtualGroupFamilyResponse, null]> => {
const client = await getClient();
return await client.virtualGroup.getGlobalVirtualGroupFamily(params).then(resolve, commonFault)
}

export const getSpUrlByBucketName = async (bucketName: string): Promise<ErrorResponse | [string, null]> => {
const client = await getClient();

return await client.sp.getSPUrlByBucket(bucketName).then(resolve, commonFault)
}
return await client.virtualGroup.getGlobalVirtualGroupFamily(params).then(resolve, commonFault);
};
20 changes: 7 additions & 13 deletions apps/dcellar-web-ui/src/modules/bucket/components/DetailDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import { CopyText } from '@/components/common/CopyText';
import { Label } from '@/modules/buckets/List/components/BucketDetail';
import BucketIcon from '@/public/images/buckets/bucket-icon.svg';
import { DCDrawer } from '@/components/common/DCDrawer';
import { getClient } from '@/base/client';
import { SpItem } from '@/store/slices/sp';
import { getPrimarySpInfo } from '@/store/slices/sp';
import { useAsyncEffect } from 'ahooks';
import dayjs from 'dayjs';
import { DCButton } from '@/components/common/DCButton';
Expand All @@ -32,7 +31,6 @@ interface DetailDrawerProps {}
export const DetailDrawer = memo<DetailDrawerProps>(function DetailDrawer() {
const dispatch = useAppDispatch();
const { editDetail, quotas, bucketInfo } = useAppSelector((root) => root.bucket);
const { allSps } = useAppSelector((root) => root.sp);
const isOpen = !!editDetail.BucketName;
const quota = quotas[editDetail.BucketName];
const bucket = bucketInfo[editDetail.BucketName] || {};
Expand Down Expand Up @@ -217,17 +215,13 @@ export const DetailDrawer = memo<DetailDrawerProps>(function DetailDrawer() {
}, [editDetail.BucketName, dispatch]);

useAsyncEffect(async () => {
if (!editDetail.BucketName || editDetail.PrimarySpAddress) return;
const client = await getClient();
const endpoint = await client.sp.getSPUrlByBucket(editDetail.BucketName);
const primarySp = allSps.find((sp: SpItem) => sp.endpoint === endpoint) as SpItem;
dispatch(
setEditDetail({
...editDetail,
PrimarySpAddress: primarySp.operatorAddress,
}),
if (!bucket.BucketName || editDetail.PrimarySpAddress) return;
const sp = await dispatch(
getPrimarySpInfo(bucket.BucketName, +bucket.GlobalVirtualGroupFamilyId),
);
}, [editDetail]);
if (!sp) return;
dispatch(setEditDetail({ ...editDetail, PrimarySpAddress: sp.operatorAddress }));
}, [bucket.BucketName, editDetail]);

const onClose = () => {
dispatch(setEditDetail({} as BucketItem));
Expand Down
32 changes: 20 additions & 12 deletions apps/dcellar-web-ui/src/store/slices/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { AppDispatch, AppState, GetState } from '@/store';
import { getSpOffChainData } from '@/store/slices/persist';
import { getBucketReadQuota, getUserBuckets, headBucket } from '@/facade/bucket';
import { toast } from '@totejs/uikit';
import { omit } from 'lodash-es';
import { getPrimarySpInfo } from './sp';
import { find, omit } from 'lodash-es';
import { getPrimarySpInfo, setPrimarySpInfos, SpItem } from './sp';
import { GetUserBucketsResponse, IQuotaProps } from '@bnb-chain/greenfield-js-sdk';
import { BucketInfo } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/types';
import {
Expand Down Expand Up @@ -148,7 +148,7 @@ export const setupBucket =
export const setupBuckets =
(address: string, forceLoading = false) =>
async (dispatch: AppDispatch, getState: GetState) => {
const { oneSp, spInfo } = getState().sp;
const { oneSp, spInfo, allSps } = getState().sp;
const { buckets, loading } = getState().bucket;
const sp = spInfo[oneSp];
if (loading) return;
Expand All @@ -161,15 +161,23 @@ export const setupBuckets =
toast.error({ description: error || res?.message });
return;
}
const bucketList = res.body?.map((bucket) => {
return {
...bucket,
BucketInfo: {
...bucket.BucketInfo,
},
};
});
dispatch(setBucketList({ address, buckets: bucketList || [] }));
const bucketList =
res.body?.map((bucket) => {
return {
...bucket,
BucketInfo: {
...bucket.BucketInfo,
},
};
}) || [];

const bucketSpInfo = bucketList.map((b) => ({
bucketName: b.BucketInfo.BucketName,
sp: find<SpItem>(allSps, (sp) => sp.id === b.Vgf.PrimarySpId)!,
}));

dispatch(setPrimarySpInfos(bucketSpInfo));
dispatch(setBucketList({ address, buckets: bucketList }));
};

export const setupBucketQuota =
Expand Down
15 changes: 9 additions & 6 deletions apps/dcellar-web-ui/src/store/slices/sp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,22 @@ export const spSlice = createSlice({
const { bucketName, sp } = payload;
state.primarySpInfo[bucketName] = sp;
},
setPrimarySpInfos(
state,
{ payload }: PayloadAction<Array<{ bucketName: string; sp: SpItem }>>,
) {
payload.forEach(({ bucketName, sp }) => {
state.primarySpInfo[bucketName] = sp;
});
},
updateSps(state, { payload }: PayloadAction<string[]>) {
state.sps = state.sps.filter((sp) => payload.includes(sp.operatorAddress));
// state.oneSp = payload[0];
},
filterSps(state, { payload }: PayloadAction<string[]>) {
state.sps = state.sps.filter((s) => !payload.includes(s.operatorAddress));
// const len = state.sps.length;
// state.oneSp = state.sps[random(0, len - 1)]?.operatorAddress;
},
},
});

export const { setStorageProviders, setPrimarySpInfo, updateSps, filterSps, setSpMeta } =
export const { setStorageProviders, setPrimarySpInfo, setPrimarySpInfos, updateSps, setSpMeta } =
spSlice.actions;

export const setupStorageProviders = () => async (dispatch: AppDispatch, getState: GetState) => {
Expand Down

0 comments on commit d59f222

Please sign in to comment.