-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[CHORE] Identifier relationships #6845
Conversation
Asset Size Report for 63b4f0d IE11 Builds The size of the library EmberData has increased by 589.0 B (298.0 B compressed) which exceeds the failure threshold of 15 bytes.WarningsThe uncompressed size of the package @ember-data/store has increased by 493.0 B. Changeset
Full Asset Analysis (IE11)
Modern Builds The size of the library EmberData has increased by 441.0 B (220.0 B compressed) which exceeds the failure threshold of 15 bytes.WarningsThe uncompressed size of the package @ember-data/store has increased by 442.0 B. Changeset
Full Asset Analysis (Modern)
Modern Builds (No Rollup) The size of the library EmberData has increased by 1.55 KB (344.0 B compressed) which exceeds the failure threshold of 15 bytes.WarningsThe uncompressed size of the package @ember-data/store has increased by 482.0 B. Changeset
Full Asset Analysis (Modern)
|
Performance Report for 63b4f0d Relationship Analysis
|
5cbb521
to
86c6450
Compare
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.
Flushing wip comments
@@ -237,21 +232,18 @@ export default class ManyRelationship extends Relationship { | |||
return payload; | |||
} | |||
|
|||
updateData(data, initial) { | |||
let recordDatas: RelationshipRecordData[] | undefined; | |||
updateData(data) { |
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 happened to initial
@@ -154,45 +161,35 @@ export default class ManyRelationship extends Relationship { | |||
this.notifyHasManyChange(); | |||
} | |||
|
|||
computeChanges(recordDatas: RelationshipRecordData[] = []) { | |||
computeChanges(identifiers: StableRecordIdentifier[] = []) { |
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.
Note to self, this method changed
this.key = relationshipMeta.key || null; | ||
this.storeWrapper = storeWrapper; | ||
this.store = storeWrapper._store; | ||
this.key = relationshipMeta.key || '--implicit'; |
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.
Possible collisions, check other checks for key
|
||
export default DS.JSONAPISerializer.extend({ | ||
normalizeResponse(store, primaryModelClass, payload) { | ||
export default class Serializer { |
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.
👍
@@ -38,7 +40,9 @@ export interface RecordDataStoreWrapper { | |||
notifyHasManyChange(modelName: string, id: string, clientId: string | null | undefined, key: string): void; | |||
notifyHasManyChange(modelName: string, id: string | null, clientId: string | null | undefined, key: string): void; | |||
|
|||
recordDataFor(modelName: string, id: string, clientId?: string): unknown; | |||
recordDataFor(modelName: string, id: string, clientId?: null | string): RecordData | RelationshipRecordData; |
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.
I think returning RecordData
is the correct signature here. RelationshipRecordData
implements RecordData
and it could also be something else that implements RecordData
@@ -1,5 +1,7 @@ | |||
import { RelationshipsSchema, AttributesSchema } from './record-data-schemas'; | |||
import { BRAND_SYMBOL } from './utils/brand'; | |||
import { RecordData } from './record-data'; | |||
import { RelationshipRecordData } from '@ember-data/record-data/-private/ts-interfaces/relationship-record-data'; |
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.
Should we do the .default import here?
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.
yeah this predates that work, I'll rebase it and run the lint fix
@@ -26,10 +24,9 @@ export interface RelationshipRecordData extends RecordData { | |||
id: string | null; | |||
clientId: string | null; | |||
isEmpty(): boolean; | |||
identifier: StableRecordIdentifier; |
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.
How does this compare to the getter?
@@ -16,14 +19,28 @@ interface InternalModel { | |||
_recordData: RecordData; | |||
} | |||
|
|||
const IdentifierCache = new WeakMap<StableRecordIdentifier, RecordData>(); | |||
|
|||
export function setRecordDataFor(identifier: StableRecordIdentifier, recordData: RecordData) { |
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.
Can we say identifier in this method name somewhere please, especially as recordDataFor has multiple signatures
if (!identifier.id) { | ||
return true; | ||
} | ||
const recordData = peekRecordData(identifier); |
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.
Can we leave a comment here as to the logic/sideeffect this uses, a couple tests to confirm the behavior might also be great but wouldn't want to block but at least file an issue please
} | ||
|
||
export class Graph { | ||
_queued: { belongsTo: any[]; hasMany: any[] } = { belongsTo: [], hasMany: [] }; |
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.
Probably shouldn't be anys
} | ||
|
||
unload(identifier: StableRecordIdentifier) { | ||
const relationships = this.identifiers.get(identifier); |
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.
Const
backburner.join(() => { | ||
// TODO this join seems to only be necessary for | ||
// some older style tests (causes 7 failures if removed) | ||
backburner.schedule('flushRelationships', this, this.flush); |
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.
Lets name this pushRelationshipPayloads
@@ -44,7 +43,7 @@ export default class RecordDataDefault implements RelationshipRecordData { | |||
_scheduledDestroy: any; | |||
_isDeleted: boolean; | |||
_isDeletionCommited: boolean; | |||
private identifier: RecordIdentifier; | |||
public identifier: RecordIdentifier; |
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.
This should probably be private
// relationship of the dematerialization: this is done so the relationship can | ||
// notify its inverse which needs to update state | ||
// | ||
// If the inverse is sync, unloading this record is treated as a client-side |
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.
Please move this comment to the right place
9c10069
to
63b4f0d
Compare
Completed in #7470 |
Refactors the internals of our relationship layer to use identifiers and avoid RecordData while keeping the API 1:1. This will allow us to refactor the relationship layer more substantially more neatly.
The ultimate goal for Project Trim is to disentangle the relationship layer enough that we can disentangle more of the relationship fetch logic from the store more easily as well as simplify the path for landing Singleton RecordData.
The ultimate goal for the Relationship Refactor is to speed up the relationship layer. While this does provide a boost, we still spend close to 700ms in relationship setup codepaths that are unneeded on the performance benchmark.