Skip to content

Commit

Permalink
fix: query error after switching collection (#593)
Browse files Browse the repository at this point in the history
Signed-off-by: ryjiang <[email protected]>
  • Loading branch information
shanghaikid authored Jul 19, 2024
1 parent 8a2cd10 commit b25477a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions client/src/hooks/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DataTypeStringEnum, MIN_INT64 } from '@/consts';
import { CollectionService } from '@/http';
import { CollectionFullObject, FieldObject } from '@server/types';

// TODO: refactor this, a little bit messy
export const useQuery = (params: {
collection: CollectionFullObject;
fields: FieldObject[];
Expand Down Expand Up @@ -69,7 +70,8 @@ export const useQuery = (params: {
// query function
const query = async (
page: number = currentPage,
consistency_level = consistencyLevel
consistency_level = consistencyLevel,
_outputFields = outputFields
) => {
if (!collection || !collection.loaded) return;
const _expr = getPageExpr(page);
Expand All @@ -79,7 +81,7 @@ export const useQuery = (params: {
try {
const queryParams = {
expr: _expr,
output_fields: outputFields,
output_fields: _outputFields,
limit: pageSize || 10,
consistency_level,
// travel_timestamp: timeTravelInfo.timestamp,
Expand Down Expand Up @@ -141,6 +143,7 @@ export const useQuery = (params: {
const reset = () => {
setCurrentPage(0);
setQueryResult({ data: [], latency: 0 });

pageCache.current.clear();
};

Expand All @@ -155,8 +158,13 @@ export const useQuery = (params: {
reset();
// get count;
count();

// update output fields, then query again
const newOutputFields = fields.map(i => i.name) || [];
setOutputFields(newOutputFields);

// do the query
query();
query(currentPage, consistencyLevel, newOutputFields);
}, [expr, pageSize, collection.collection_name]);

return {
Expand Down

0 comments on commit b25477a

Please sign in to comment.