Skip to content

Commit

Permalink
CB-4686 makes onDataOutdated execution manual
Browse files Browse the repository at this point in the history
  • Loading branch information
s.teleshev committed Mar 20, 2024
1 parent 474c7b4 commit 0530eb4
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ type NewConfiguration = AuthConfiguration & { [NEW_CONFIGURATION_SYMBOL]: boolea

@injectable()
export class AuthConfigurationsResource extends CachedMapResource<string, AuthConfiguration, GetAuthProviderConfigurationsQueryVariables> {
constructor(private readonly graphQLService: GraphQLService, permissionsResource: SessionPermissionsResource) {
constructor(
private readonly graphQLService: GraphQLService,
permissionsResource: SessionPermissionsResource,
) {
super(() => new Map(), []);

permissionsResource.require(this, EAdminPermission.admin).outdateResource(this);
Expand All @@ -51,6 +54,7 @@ export class AuthConfigurationsResource extends CachedMapResource<string, AuthCo
}

this.set(configuration.id, configuration);
this.onDataOutdated.execute(configuration.id);
});

return this.get(config.id)!;
Expand Down
4 changes: 4 additions & 0 deletions webapp/packages/core-authentication/src/UserInfoResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ export class UserInfoResource extends CachedDataResource<UserInfo | null, void,
if (this.data) {
this.data.configurationParameters[key] = value;
}

this.onDataOutdated.execute();
});

return this.data;
Expand Down Expand Up @@ -210,6 +212,8 @@ export class UserInfoResource extends CachedDataResource<UserInfo | null, void,
delete this.data?.configurationParameters[item];
}
});

this.onDataOutdated.execute();
});
return this.data;
}
Expand Down
2 changes: 2 additions & 0 deletions webapp/packages/core-authentication/src/UsersResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ export class UsersResource extends CachedMapResource<string, AdminUser, UserReso
if (user) {
user.authRole = authRole;
}

this.onDataOutdated.execute(userId);
});

if (!skipUpdate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export class ConnectionExecutionContextResource extends CachedMapResource<string
}

async create(key: IConnectionInfoParams, defaultCatalog?: string, defaultSchema?: string): Promise<IConnectionExecutionContextInfo> {
return await this.performUpdate(getContextBaseId(key, ''), [], async () => {
const contextKey = getContextBaseId(key, '');
return await this.performUpdate(contextKey, [], async () => {
const { context } = await this.graphQLService.sdk.executionContextCreate({
...key,
defaultCatalog,
Expand All @@ -85,6 +86,8 @@ export class ConnectionExecutionContextResource extends CachedMapResource<string
this.markOutdated(); // TODO: should be removed, currently multiple contexts for same connection may change catalog/schema for all contexts of connection
});

this.onDataOutdated.execute(contextKey);

return this.get(baseContext.id)!;
});
}
Expand All @@ -107,6 +110,7 @@ export class ConnectionExecutionContextResource extends CachedMapResource<string

context.defaultCatalog = defaultCatalog;
context.defaultSchema = defaultSchema;
this.onDataOutdated.execute(contextId);
});

this.markOutdated();
Expand All @@ -126,6 +130,7 @@ export class ConnectionExecutionContextResource extends CachedMapResource<string
connectionId: context.connectionId,
projectId: context.projectId,
});
this.onDataOutdated.execute(contextId);
});

runInAction(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export const ConnectionFolderProjectKey = resourceKeyAliasFactory('@connection-f

@injectable()
export class ConnectionFolderResource extends CachedMapResource<IConnectionFolderParam, ConnectionFolder> {
constructor(private readonly graphQLService: GraphQLService, sessionDataResource: SessionDataResource, appAuthService: AppAuthService) {
constructor(
private readonly graphQLService: GraphQLService,
sessionDataResource: SessionDataResource,
appAuthService: AppAuthService,
) {
super();

appAuthService.requireAuthentication(this);
Expand Down Expand Up @@ -70,6 +74,7 @@ export class ConnectionFolderResource extends CachedMapResource<IConnectionFolde
folderPath: key.folderId,
});
this.delete(key);
this.onDataOutdated.execute(key);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ export class ConnectionInfoResource extends CachedMapResource<IConnectionInfoPar
projectId: connectionKey.projectId,
connectionId: connectionKey.connectionId,
});

this.onDataOutdated.execute(connectionKey);
return subjects;
});

Expand Down Expand Up @@ -396,6 +398,7 @@ export class ConnectionInfoResource extends CachedMapResource<IConnectionInfoPar
...this.getIncludesMap(key),
});
this.set(createConnectionParam(connection), connection);
this.onDataOutdated.execute(key);
});

return this.get(key)!;
Expand All @@ -413,6 +416,7 @@ export class ConnectionInfoResource extends CachedMapResource<IConnectionInfoPar
});

this.set(createConnectionParam(connection), connection);
this.onDataOutdated.execute(key);
});

return this.get(key)!;
Expand All @@ -428,6 +432,7 @@ export class ConnectionInfoResource extends CachedMapResource<IConnectionInfoPar
});

this.set(createConnectionParam(connection), connection);
this.onDataOutdated.execute(key);
});
return this.get(key)!;
}
Expand All @@ -442,6 +447,7 @@ export class ConnectionInfoResource extends CachedMapResource<IConnectionInfoPar
});

this.set(createConnectionParam(connection), connection);
this.onDataOutdated.execute(key);
});

const connection = this.get(key)!;
Expand All @@ -457,6 +463,7 @@ export class ConnectionInfoResource extends CachedMapResource<IConnectionInfoPar
await ResourceKeyUtils.forEachAsync(key, async key => {
await this.performUpdate(key, [], async () => {
await this.graphQLService.sdk.deleteConnection({ projectId: key.projectId, connectionId: key.connectionId });
this.onDataOutdated.execute(key);
});
this.delete(key);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export class NavTreeResource extends CachedMapResource<string, string[], Record<
await this.graphQLService.sdk.navDeleteNodes({ nodePaths: [path] });
deletedPaths.push(path);
}
this.onDataOutdated.execute(key);

This comment has been minimized.

Copy link
@Wroud

Wroud Mar 21, 2024

Member

it's better to move it to the end of performUpdate

} finally {
runInAction(() => {
const deletedNodes: string[] = [];
Expand Down Expand Up @@ -223,8 +224,9 @@ export class NavTreeResource extends CachedMapResource<string, string[], Record<

async moveTo(key: ResourceKeySimple<string>, target: string): Promise<void> {
const parents = Array.from(new Set(ResourceKeyUtils.mapArray(key, key => this.navNodeInfoResource.get(key)?.parentId).filter(isDefined)));
const parentsKey = resourceKeyList(parents);

await this.performUpdate(resourceKeyList(parents), [], async () => {
await this.performUpdate(parentsKey, [], async () => {
this.markLoading(target, true);

try {
Expand All @@ -235,6 +237,7 @@ export class NavTreeResource extends CachedMapResource<string, string[], Record<

this.moveToNode(key, target);
this.markLoaded(target);
this.onDataOutdated.execute(parentsKey);
} finally {
this.markLoading(target, false);
}
Expand Down Expand Up @@ -272,6 +275,7 @@ export class NavTreeResource extends CachedMapResource<string, string[], Record<

this.markTreeOutdated(parentId);
this.markLoaded(node.id);
this.onDataOutdated.execute(parentId);
return parts.join('/');
} finally {
this.markLoading(node.id, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export class ResourceManagerResource extends CachedTreeResource<RmResourceInfo,
await this.loader(to, []);

this.moveSync(from, to, this.get(to)!);
this.onDataOutdated.execute(from);
});
}

Expand All @@ -144,6 +145,7 @@ export class ResourceManagerResource extends CachedTreeResource<RmResourceInfo,
}

Object.assign(properties, propertiesPatch);
this.onDataOutdated.execute(key);
});

return properties;
Expand Down Expand Up @@ -195,6 +197,7 @@ export class ResourceManagerResource extends CachedTreeResource<RmResourceInfo,
});

this.delete(path);
this.onDataOutdated.execute(path);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ export class SharedProjectsResource extends CachedMapResource<string, SharedProj

deleted.push(projectId);
});

this.onDataOutdated.execute(key);
});
} finally {
if (deleted.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,6 @@ export abstract class CachedResource<
{
success: () => {
if (loaded) {
this.onDataOutdated.execute(key); // TODO: probably need to remove, we need to notify any related resources that subscribed to .onOutdate, to recursively outdate them
this.dataUpdate(key);
}
},
Expand Down
4 changes: 4 additions & 0 deletions webapp/packages/core-root/src/ServerConfigResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export class ServerConfigResource extends CachedDataResource<ServerConfig | null
await this.performUpdate(undefined, undefined, async () => {
await this.graphQLService.sdk.updateProductConfiguration({ configuration });
this.setData(await this.loader());
this.onDataOutdated.execute();
});
}

Expand All @@ -256,6 +257,8 @@ export class ServerConfigResource extends CachedDataResource<ServerConfig | null
});
this.setData(await this.loader());
}

this.onDataOutdated.execute();
},
() => !this.isNavigatorSettingsChanged() && (!this.isChanged() || skipConfigUpdate),
);
Expand All @@ -271,6 +274,7 @@ export class ServerConfigResource extends CachedDataResource<ServerConfig | null
});

this.setData(await this.loader());
this.onDataOutdated.execute();
},
() => !this.isChanged() && !onlyRestart,
);
Expand Down

0 comments on commit 0530eb4

Please sign in to comment.