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

sort collections list by name #555

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 19 additions & 7 deletions client/src/context/Data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ export const DataProvider = (props: { children: React.ReactNode }) => {
try {
// set loading true
setLoading(true);
// set collections
setCollections([]);
// fetch collections
const res = await CollectionService.getCollections();
// check state
Expand Down Expand Up @@ -343,6 +345,18 @@ export const DataProvider = (props: { children: React.ReactNode }) => {
};

useEffect(() => {
const clear = () => {
// clear collections
setCollections([]);
// clear database
setDatabases([]);
// set connected to false
setConnected(false);
// remove all listeners when component unmount
socket.current?.offAny();
socket.current?.disconnect();
};

if (isAuth) {
// update database get from auth
setDatabase(authReq.database);
Expand Down Expand Up @@ -370,14 +384,12 @@ export const DataProvider = (props: { children: React.ReactNode }) => {
socket.current?.disconnect();
});
} else {
socket.current?.disconnect();
// clear collections
setCollections([]);
// clear database
setDatabases([]);
// set connected to false
setConnected(false);
clear();
}

return () => {
clear();
};
}, [isAuth]);

useEffect(() => {
Expand Down
22 changes: 7 additions & 15 deletions server/src/collections/collections.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,12 @@ export class CollectionsService {
// get all collections details
async getAllCollections(
clientId: string,
collectionName: string[] = []
collections: string[] = []
): Promise<CollectionObject[]> {
const cache = clientCache.get(clientId);

// clear collectionsQueue
if (collectionName.length === 0) {
// clear collectionsQueue if we fetch all collections
if (collections.length === 0) {
cache.collectionsQueue.stop();
cache.collectionsQueue = new SimpleQueue<string>();
}
Expand All @@ -460,12 +460,15 @@ export class CollectionsService {

// get target collections details
const targetCollections = allCollections.data.filter(
d => collectionName.indexOf(d.name) !== -1
d => collections.indexOf(d.name) !== -1
);

const targets =
targetCollections.length > 0 ? targetCollections : allCollections.data;

// sort targets by name
targets.sort((a, b) => a.name.localeCompare(b.name));

// get all collection details
for (let i = 0; i < targets.length; i++) {
const collection = targets[i];
Expand Down Expand Up @@ -496,17 +499,6 @@ export class CollectionsService {
}, 5);
}

// sort data by loadedPercentage and has index or not, then createdTime.
data.sort((a, b) => {
if (a.loadedPercentage === b.loadedPercentage && a.schema && b.schema) {
if (a.schema.hasVectorIndex === b.schema.hasVectorIndex) {
return b.createdTime - a.createdTime;
}
return a.schema.hasVectorIndex ? -1 : 1;
}
return (b.loadedPercentage || 0) - (a.loadedPercentage || 0);
});

// return data
return data;
}
Expand Down
Loading