Skip to content

Commit

Permalink
Merge pull request #308 from zilliztech/attu-304
Browse files Browse the repository at this point in the history
using query for count
  • Loading branch information
shanghaikid authored Nov 7, 2023
2 parents f259d1f + 448f495 commit 65679ef
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 17 deletions.
2 changes: 1 addition & 1 deletion client/src/http/Axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const url =

const axiosInstance = axios.create({
baseURL: `${url}/api/v1`,
timeout: 60000,
timeout: 60000 * 5, // 5 minutes
});

axiosInstance.interceptors.request.use(
Expand Down
6 changes: 3 additions & 3 deletions client/src/http/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class CollectionHttp extends BaseModel implements CollectionView {
}

get _aliases() {
return this.aliases;
return this.aliases || [];
}

get _desc() {
Expand Down Expand Up @@ -234,11 +234,11 @@ export class CollectionHttp extends BaseModel implements CollectionView {
}

get _replicas(): Replica[] {
return this.replicas;
return this.replicas || [];
}

get _enableDynamicField(): boolean {
return this.schema.enable_dynamic_field;
return this.schema && this.schema.enable_dynamic_field;
}

get _schema() {
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/en/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const collectionTrans = {
noData: 'No Collection',

rowCount: 'Approx Count',
count: 'Entity Count',

create: 'Collection',
delete: 'delete',
Expand Down
2 changes: 1 addition & 1 deletion client/src/i18n/en/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const dialogTrans = {
loadTitle: `Load {{type}}`,

loadContent: `You are trying to load a {{type}} with data. Only loaded {{type}} can be searched.`,
releaseContent: `You are trying to release a {{type}} with data. Please be aware that the data will no longer be available for search.`,
releaseContent: `You are trying to release {{type}} with data. Please be aware that the data will no longer be available for search.`,

createTitle: `Create {{type}} on "{{name}}"`,
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/i18n/en/overview.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const overviewTrans = {
load: 'Loaded Collections',
all: 'All Collections',
data: 'Entities',
data: 'Approx Entities',
rows: '{{number}}',
loading: 'Loading Collections',
sysInfo: 'System Info',
Expand Down
17 changes: 11 additions & 6 deletions client/src/pages/overview/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { LOADING_STATE, MILVUS_DEPLOY_MODE } from '@/consts';
import { WS_EVENTS, WS_EVENTS_TYPE } from '@server/utils/Const';
import { useNavigationHook } from '@/hooks';
import { CollectionHttp, MilvusHttp } from '@/http';
import { ShowCollectionsType } from '@/types/Milvus';
import { ALL_ROUTER_TYPES } from '@/router/Types';
import { checkLoading, checkIndexBuilding, formatNumber } from '@/utils';
import CollectionCard from './collectionCard/CollectionCard';
Expand Down Expand Up @@ -106,6 +107,11 @@ const SysCard = (data: {
);
};

type statisticsType = {
collectionCount: number;
totalData: number;
};

const Overview = () => {
useNavigationHook(ALL_ROUTER_TYPES.OVERVIEW);
const { database, databases, data } = useContext(dataContext);
Expand All @@ -114,10 +120,7 @@ const Overview = () => {
const { t: overviewTrans } = useTranslation('overview');
const { t: collectionTrans } = useTranslation('collection');
const { t: successTrans } = useTranslation('success');
const [statistics, setStatistics] = useState<{
collectionCount: number;
totalData: number;
}>({
const [statistics, setStatistics] = useState<statisticsType>({
collectionCount: 0,
totalData: 0,
});
Expand All @@ -127,8 +130,10 @@ const Overview = () => {

const fetchData = useCallback(async () => {
setLoading(true);
const res = await CollectionHttp.getStatistics();
const collections = await CollectionHttp.getCollections();
const res = (await CollectionHttp.getStatistics()) as statisticsType;
const collections = await CollectionHttp.getCollections({
type: ShowCollectionsType.InMemory,
});
const hasLoadingOrBuildingCollection = collections.some(
v => checkLoading(v) || checkIndexBuilding(v)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const CollectionCard: FC<CollectionCardProps> = ({
</li>
) : null}
<li>
<Typography>{collectionTrans('rowCount')}</Typography>:
<Typography>{collectionTrans('count')}</Typography>:
<Typography className={classes.rowCount}>{rowCount}</Typography>
</li>
</ul>
Expand Down
28 changes: 24 additions & 4 deletions server/src/collections/collections.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
GetQuerySegmentInfoReq,
GePersistentSegmentInfoReq,
CompactReq,
CountReq,
} from '@zilliz/milvus2-sdk-node';
import { throwErrorFromSDK, findKeyValue, genRows, ROW_COUNT } from '../utils';
import { QueryDto, ImportSampleDto, GetReplicasDto } from './dto';
Expand Down Expand Up @@ -75,6 +76,12 @@ export class CollectionsService {
return res;
}

async count(data: CountReq) {
const res = await this.milvusService.client.count(data);
throwErrorFromSDK(res.status);
return res;
}

async insert(data: InsertReq) {
const res = await this.milvusService.client.insert(data);
throwErrorFromSDK(res.status);
Expand Down Expand Up @@ -223,13 +230,26 @@ export class CollectionsService {
if (res.data.length > 0) {
for (const item of res.data) {
const { id, name } = item;
const collectionStatistics = await this.getCollectionStatistics({
collection_name: name,
});

let count: number | string;

try {
const countRes = await this.count({
collection_name: name,
});
count = countRes.data;
} catch (error) {
const collectionStatisticsRes = await this.getCollectionStatistics({
collection_name: name,
});
count = collectionStatisticsRes.data.row_count;
}

data.push({
id,
collection_name: name,
rowCount: findKeyValue(collectionStatistics.stats, ROW_COUNT),
rowCount: count,
...item,
});
}
}
Expand Down

0 comments on commit 65679ef

Please sign in to comment.