Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
private readonly sessionDataResource: SessionDataResource,
private readonly userInfoResource: UserInfoResource,
private readonly projectInfoResource: ProjectInfoResource,
appAuthService: AppAuthService,
private readonly appAuthService: AppAuthService,
) {
super();

Expand Down Expand Up @@ -119,7 +119,13 @@
() => CachedMapAllKey,
() => CachedMapAllKey,
);
this.projectInfoResource.onDataOutdated.addHandler(() => this.markTreeOutdated(resourceKeyList(this.keys)));
this.projectInfoResource.onDataOutdated.addHandler(data => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we preloaded all projects. If we change project we don't really want to update all project tree nodes info. We just want project we switched to, or projects we have changed. data is an array of projects

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise there are abused network with requests about all projects info

if (isResourceAlias(data)) {
return;
} else {
this.markTreeOutdated(data);
}
});
this.sessionDataResource.onDataOutdated.addHandler(() => this.markTreeOutdated(resourceKeyList(this.keys)));
this.userInfoResource.onUserChange.addHandler(
action(() => {
Expand Down Expand Up @@ -279,7 +285,7 @@
await this.onNodeMove.execute({ key, target });
}

async setFilter(nodePath: string, include?: string[], exclude?: string[]) {

Check warning on line 288 in webapp/packages/core-navigation-tree/src/NodesManager/NavTreeResource.ts

View workflow job for this annotation

GitHub Actions / Frontend / Lint

Missing return type on function
await this.graphQLService.sdk.navSetFolderFilter({
nodePath,
exclude,
Expand Down Expand Up @@ -551,7 +557,7 @@
return nestedChildren;
}

private setNavObject(data: NavNodeChildrenQuery | NavNodeChildrenQuery[], offset: number, limit: number): void {
private setNavObject(data: NavNodeChildrenQuery | NavNodeChildrenQuery[], offset: number, limit: number | undefined): void {
if (Array.isArray(data)) {
if (data.length === 0) {
return;
Expand Down Expand Up @@ -589,12 +595,12 @@
}
}

private insertSlice(data: NavNodeChildrenQuery, offset: number, limit: number): string[] {
private insertSlice(data: NavNodeChildrenQuery, offset: number, limit: number | undefined): string[] {
let children = [...(this.get(data.parentPath) || [])];

children.splice(offset, limit, ...data.navNodeChildren.map(node => node.uri));
children.splice(offset, limit ?? children.length, ...data.navNodeChildren.map(node => node.uri));

if (data.navNodeChildren.length < limit) {
if (limit !== undefined && data.navNodeChildren.length < limit) {
children.splice(offset + data.navNodeChildren.length, children.length - offset - data.navNodeChildren.length);
}

Expand All @@ -603,7 +609,36 @@
return children;
}

private async loadNodeChildren(parentPath: string, offset: number, limit: number): Promise<NavNodeChildrenQuery> {
async loadAllChildren(nodeId: string): Promise<void> {
if (!this.appAuthService.authenticated || this.isLoading(nodeId)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since resource is requires user to be authenticated I also added this logic here. otherwise we get erors on login screen
this.isLoading() - here stands for reducing requests amount. cause different trees in the app can trigger the same request

return;
}

const pageKey = CachedResourceOffsetPageKey(0, 0).setParent(CachedResourceOffsetPageTargetKey(nodeId));
const hasPage = this.offsetPagination.getPageInfo(pageKey) !== undefined;

if (hasPage && !this.isOutdated(nodeId)) {
return;
}

this.markLoading(nodeId, true);
try {
const navNodeChildren = await this.loadNodeChildren(nodeId, 0, undefined);
const uris = navNodeChildren.navNodeChildren.map(node => node.uri);

runInAction(() => {
this.setNavObject(navNodeChildren, 0, undefined);
this.offsetPagination.setPage(CachedResourceOffsetPageKey(0, uris.length).setParent(CachedResourceOffsetPageTargetKey(nodeId)), uris, false);
this.markLoaded(nodeId);
this.markUpdated(nodeId);
this.markUpdated(resourceKeyList(uris));
});
} finally {
this.markLoading(nodeId, false);
}
}

private async loadNodeChildren(parentPath: string, offset: number, limit: number | undefined): Promise<NavNodeChildrenQuery> {
const metadata = this.metadata.get(parentPath);
const { navNodeChildren, navNodeInfo } = await this.graphQLService.sdk.navNodeChildren({
parentPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,9 @@ export function useElementsTree(options: IOptions): IElementsTree {
const pageInfo = navTreeResource.offsetPagination.getPageInfo(
CachedResourceOffsetPageKey(0, 0).setParent(CachedResourceOffsetPageTargetKey(nodeId)),
);
const hasMorePages = pageInfo && pageInfo.end === undefined;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also reduces the amount of requests and also it is more correct for the logic below cause it actually tries to get next page


if (pageInfo) {
if (hasMorePages) {
const lastOffset = getNextPageOffset(pageInfo);
for (let offset = 0; offset < lastOffset; offset += navTreeResource.childrenLimit) {
await navTreeResource.load(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2025 DBeaver Corp and others
* Copyright (C) 2020-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,14 @@ import {
} from '@cloudbeaver/core-connections';
import { injectable } from '@cloudbeaver/core-di';
import { Executor, type IExecutor, type ISyncExecutor, SyncExecutor } from '@cloudbeaver/core-executor';
import { EObjectFeature, NavNodeInfoResource, NavNodeManagerService, NavTreeResource, ROOT_NODE_PATH } from '@cloudbeaver/core-navigation-tree';
import {
EObjectFeature,
NavNodeInfoResource,
NavNodeManagerService,
NavTreeResource,
ProjectsNavNodeService,
ROOT_NODE_PATH,
} from '@cloudbeaver/core-navigation-tree';
import {
CACHED_RESOURCE_DEFAULT_PAGE_OFFSET,
CachedResourceOffsetPageKey,
Expand Down Expand Up @@ -46,6 +53,7 @@ interface INavigationNodeShowData {
NavNodeExtensionsService,
NavNodeInfoResource,
NavTreeResource,
ProjectsNavNodeService,
])
export class NavigationTreeService extends View<string> {
readonly treeState: MetadataMap<string, ITreeNodeState>;
Expand All @@ -59,6 +67,7 @@ export class NavigationTreeService extends View<string> {
private readonly navNodeExtensionsService: NavNodeExtensionsService,
private readonly navNodeInfoResource: NavNodeInfoResource,
private readonly navTreeResource: NavTreeResource,
private readonly projectsNavNodeService: ProjectsNavNodeService,
) {
super();

Expand Down Expand Up @@ -131,11 +140,15 @@ export class NavigationTreeService extends View<string> {
return false;
}

await this.navTreeResource.load(
CachedResourceOffsetPageKey(CACHED_RESOURCE_DEFAULT_PAGE_OFFSET, this.navTreeResource.childrenLimit).setParent(
CachedResourceOffsetPageTargetKey(id),
),
);
if (this.isMainNode(id)) {
await this.navTreeResource.loadAllChildren(id);
} else {
await this.navTreeResource.load(
CachedResourceOffsetPageKey(CACHED_RESOURCE_DEFAULT_PAGE_OFFSET, this.navTreeResource.childrenLimit).setParent(
CachedResourceOffsetPageTargetKey(id),
),
);
}

return true;
}
Expand Down Expand Up @@ -194,6 +207,18 @@ export class NavigationTreeService extends View<string> {
});
}

// Main nodes - root, project, file system (dbvfs), scripts or datasets (rm)
private isMainNode(id: string): boolean {
if (id === ROOT_NODE_PATH) {
return true;
}
const node = this.navNodeInfoResource.get(id);
if (!node) {
return false;
}
return node.parentId === ROOT_NODE_PATH || this.projectsNavNodeService.projectTypes.includes(node.nodeType ?? '');
}

private isConnectionNode(navNodeId: string) {
const node = this.navNodeManagerService.getNode(navNodeId);
return node?.objectFeatures.includes(EObjectFeature.dataSource);
Expand Down
Loading