-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
base: canary
Are you sure you want to change the base?
Conversation
Your org has enabled the Graphite merge queue for merging into canaryAdd 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. |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
☁️ Nx Cloud ReportCI is running/has finished running commands for commit c4e599c. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 6 targets
Sent with 💌 from NxCloud. |
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
b4af180
to
3ffc832
Compare
* @example | ||
* yjsObserveDeep(yjs) -> emit when any of its deep children changed | ||
*/ | ||
export function yjsObserveDeep(yjs?: any) { |
There was a problem hiding this comment.
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?
da29f9f
to
d28dece
Compare
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); | ||
} | ||
} |
There was a problem hiding this comment.
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
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean LegacyDocProperties
?
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))) | ||
); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
d28dece
to
c4e599c
Compare
create new orm table docConfiguration
move primary store to docConfiguration