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

perf(computed): unified decorator computed to replace the old sandwich decorators (computedField, relation) by a single resolver #1207

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
8 changes: 4 additions & 4 deletions packages/agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ export default class Agent<S extends TSchema = TSchema> extends FrameworkMounter
const { isProduction, logger, typingsPath, typingsMaxDepth } = this.options;

// It allows to rebuild the full customization stack with no code customizations
this.nocodeCustomizer = new DataSourceCustomizer<S>();
this.nocodeCustomizer.addDataSource(this.customizer.getFactory());
this.nocodeCustomizer.use(this.customizationService.addCustomizations);
// this.nocodeCustomizer = new DataSourceCustomizer<S>();
// this.nocodeCustomizer.addDataSource(this.customizer.getFactory());
// this.nocodeCustomizer.use(this.customizationService.addCustomizations);

const dataSource = await this.nocodeCustomizer.getDataSource(logger);
const dataSource = await this.customizer.getDataSource(logger);
const [router] = await Promise.all([
this.getRouter(dataSource),
this.sendSchema(dataSource),
Expand Down
23 changes: 11 additions & 12 deletions packages/datasource-customizer/src/collection-customizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import DataSourceCustomizer from './datasource-customizer';
import { ActionDefinition } from './decorators/actions/types/actions';
import { BinaryMode } from './decorators/binary/types';
import { CollectionChartDefinition } from './decorators/chart/types';
import { ComputedDefinition, DeprecatedComputedDefinition } from './decorators/computed/types';
import {
ComputedDefinition,
DeprecatedComputedDefinition,
RelationDefinition,
} from './decorators/computed/types';
import mapDeprecated from './decorators/computed/utils/map-deprecated';
import DecoratorsStack from './decorators/decorators-stack';
import { HookHandler, HookPosition, HookType, HooksContext } from './decorators/hook/types';
import { OperatorDefinition } from './decorators/operators-emulate/types';
import { RelationDefinition } from './decorators/relation/types';
import { SearchDefinition } from './decorators/search/types';
import { SegmentDefinition } from './decorators/segment/types';
import { WriteDefinition } from './decorators/write/write-replace/types';
Expand Down Expand Up @@ -176,8 +179,8 @@ export default class CollectionCustomizer<
definition: DeprecatedComputedDefinition<S, N> | ComputedDefinition<S, N>,
): this => {
return this.pushCustomization(async () => {
const collectionBeforeRelations = this.stack.earlyComputed.getCollection(this.name);
const collectionAfterRelations = this.stack.lateComputed.getCollection(this.name);
const collectionBeforeRelations = this.stack.computed.getCollection(this.name);
const collectionAfterRelations = this.stack.computed.getCollection(this.name);
const canBeComputedBeforeRelations = definition.dependencies.every(field => {
try {
return !!CollectionUtils.getFieldSchema(collectionBeforeRelations, field);
Expand Down Expand Up @@ -417,7 +420,7 @@ export default class CollectionCustomizer<
*/
emulateFieldFiltering(name: TColumnName<S, N>): this {
return this.pushCustomization(async () => {
const collection = this.stack.lateOpEmulate.getCollection(this.name);
const collection = this.stack.computed.getCollection(this.name);
const field = collection.schema.fields[name] as ColumnSchema;

if (typeof field.columnType === 'string') {
Expand All @@ -443,9 +446,7 @@ export default class CollectionCustomizer<
*/
emulateFieldOperator(name: TColumnName<S, N>, operator: Operator): this {
return this.pushCustomization(async () => {
const collection = this.stack.earlyOpEmulate.getCollection(this.name).schema.fields[name]
? this.stack.earlyOpEmulate.getCollection(this.name)
: this.stack.lateOpEmulate.getCollection(this.name);
const collection = this.stack.opEmulate.getCollection(this.name);

collection.emulateFieldOperator(name, operator);
});
Expand Down Expand Up @@ -499,9 +500,7 @@ export default class CollectionCustomizer<
replacer: OperatorDefinition<S, N, C>,
): this {
return this.pushCustomization(async () => {
const collection = this.stack.earlyOpEmulate.getCollection(this.name).schema.fields[name]
? this.stack.earlyOpEmulate.getCollection(this.name)
: this.stack.lateOpEmulate.getCollection(this.name);
const collection = this.stack.opEmulate.getCollection(this.name);

collection.replaceFieldOperator(name, operator, replacer as OperatorDefinition);
});
Expand Down Expand Up @@ -547,7 +546,7 @@ export default class CollectionCustomizer<

private pushRelation(name: string, definition: RelationDefinition): this {
return this.pushCustomization(async () => {
this.stack.relation.getCollection(this.name).addRelation(name, definition);
this.stack.computed.getCollection(this.name).addRelation(name, definition);
});
}

Expand Down
Loading