[go: up one dir, main page]

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

feat(infra): doc properties by orm #8382

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from
Open

Conversation

EYHN
Copy link
Member
@EYHN EYHN commented Sep 25, 2024

create new orm table docConfiguration

move primary store to docConfiguration

Copy link
graphite-app bot commented Sep 25, 2024

Your org has enabled the Graphite merge queue for merging into canary

Add the label “merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@EYHN EYHN marked this pull request as ready for review September 25, 2024 02:32
@github-actions github-actions bot added the mod:infra Environment related issues and discussions label Sep 25, 2024
Copy link
Member Author
EYHN commented Sep 25, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @EYHN and the rest of your teammates on Graphite Graphite

Copy link
nx-cloud bot commented Sep 25, 2024

Copy link
codecov bot commented Sep 25, 2024

Codecov Report

Attention: Patch coverage is 14.87603% with 103 lines in your changes missing coverage. Please review.

Project coverage is 70.07%. Comparing base (4e30f75) to head (c4e599c).
Report is 2 commits behind head on canary.

Files with missing lines Patch % Lines
...mon/infra/src/modules/doc/stores/doc-properties.ts 0.00% 45 Missing ⚠️
packages/common/infra/src/utils/yjs-observable.ts 40.00% 24 Missing and 3 partials ⚠️
...ckages/common/infra/src/modules/doc/stores/docs.ts 0.00% 25 Missing ⚠️
...on/infra/src/modules/doc/entities/property-list.ts 0.00% 4 Missing ⚠️
...es/common/infra/src/modules/doc/entities/record.ts 0.00% 1 Missing ⚠️
.../infra/src/modules/workspace/entities/workspace.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           canary    #8382      +/-   ##
==========================================
- Coverage   70.21%   70.07%   -0.14%     
==========================================
  Files         520      523       +3     
  Lines       32961    33051      +90     
  Branches     2879     2902      +23     
==========================================
+ Hits        23142    23161      +19     
- Misses       9481     9549      +68     
- Partials      338      341       +3     
Flag Coverage Δ
server-test 76.71% <ø> (ø)
unittest 45.71% <14.87%> (-0.32%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@EYHN EYHN marked this pull request as draft September 26, 2024 16:57
@EYHN EYHN changed the title feat(infra): doc configuration feat(infra): doc properties by orm Sep 27, 2024
@github-actions github-actions bot added the test Related to test cases label Sep 27, 2024
@EYHN EYHN marked this pull request as ready for review September 27, 2024 09:32
@EYHN EYHN requested a review from pengx17 September 27, 2024 09:32
* @example
* yjsObserveDeep(yjs) -> emit when any of its deep children changed
*/
export function yjsObserveDeep(yjs?: any) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Saul-Mirone can you help review this function?

@EYHN EYHN force-pushed the eyhn/doc-configuration branch 2 times, most recently from da29f9f to d28dece Compare September 27, 2024 09:56
Comment on lines 70 to 85
updateDocPropertyInfo(id: string, config: Partial<DocCustomPropertyInfo>) {
const needMigration = !this.dbService.db.docCustomPropertyInfo.get(id);
if (needMigration) {
// if this property is not in db, we need to migration it from latency to db, only type and name is needed
const latencyId = id.replace('custom:', '');
const latency = this.getLatencyDocPropertyInfo(latencyId);
this.dbService.db.docCustomPropertyInfo.create({
id,
type:
latency?.type ??
'unknown' /* should never reach here, just for safety, we need handle unknown property type */,
name: latency?.name,
...config,
});
return;
} else {
this.dbService.db.docCustomPropertyInfo.update(id, config);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

may split the migration code for clearity

Suggested change
updateDocPropertyInfo(id: string, config: Partial<DocCustomPropertyInfo>) {
const needMigration = !this.dbService.db.docCustomPropertyInfo.get(id);
if (needMigration) {
// if this property is not in db, we need to migration it from latency to db, only type and name is needed
const latencyId = id.replace('custom:', '');
const latency = this.getLatencyDocPropertyInfo(latencyId);
this.dbService.db.docCustomPropertyInfo.create({
id,
type:
latency?.type ??
'unknown' /* should never reach here, just for safety, we need handle unknown property type */,
name: latency?.name,
...config,
});
return;
} else {
this.dbService.db.docCustomPropertyInfo.update(id, config);
}
}
updateDocPropertyInfo(id: string, config: Partial<DocCustomPropertyInfo>) {
const needMigration = !this.dbService.db.docCustomPropertyInfo.get(id);
return needMigration
? this.migrateAndCreatePropertyInfo(id, config)
: this.dbService.db.docCustomPropertyInfo.update(id, config);
}
private migrateAndCreatePropertyInfo(id: string, config: Partial<DocCustomPropertyInfo>) {
const latencyId = id.replace('custom:', '');
const latency = this.getLatencyDocPropertyInfo(latencyId);
return this.dbService.db.docCustomPropertyInfo.create({
id,
type: latency?.type ?? 'unknown',
name: latency?.name,
...config,
});
}

} from '../../db/schema/schema';
import type { WorkspaceService } from '../../workspace';

interface LatencyDocProperties {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you mean LegacyDocProperties?

Comment on lines 35 to 54
if (target instanceof YArray) {
return new Observable(subscriber => {
const refresh = () => {
if ('index' in current) {
subscriber.next(target.get(current.index));
} else {
subscriber.next(undefined);
}
};
target.observe(refresh);
return () => {
target.unobserve(refresh);
};
}).pipe(
distinctUntilChanged(),
switchMap(arr => _yjsDeepWatch(arr, path.slice(1)))
);
} else if (target instanceof YMap) {
return new Observable(subscriber => {
const refresh = () => {
if ('key' in current) {
subscriber.next(target.get(current.key));
} else {
subscriber.next(undefined);
}
};
refresh();
target.observe(refresh);
return () => {
target.unobserve(refresh);
};
}).pipe(
distinctUntilChanged(),
switchMap(arr => _yjsDeepWatch(arr, path.slice(1)))
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

the two branches are almost the same. perhaps merge them?

subscriber.next(undefined);
}
};
target.observe(refresh);
Copy link
Collaborator

Choose a reason for hiding this comment

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

refresh on init?

*/
export function yjsObserveByPath(yjs: YAbstractType<any>, path: string) {
const parsedPath = parsePath(path);
return _yjsDeepWatch(yjs, parsedPath);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if the target being watched hasn't been created yet at the time of observation? Should we also observe its parent in this case?

Copy link
Member Author

Choose a reason for hiding this comment

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

We will observe the parent until the child is created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mod:infra Environment related issues and discussions test Related to test cases
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants