|
@@ -90,13 +90,13 @@ export default async function createModels2(gql, config={create: 'Upsert', updat
|
|
|
const inTypes = name => types.find(type => type.name === name)
|
|
|
const inInputs = name => inputs.find(type => type.name === name)
|
|
|
|
|
|
- const projectionBuilder = (type, allFields=true) => {
|
|
|
- if (!allFields && type.fields[0].name !== '_id') allFields = true
|
|
|
+ const projectionBuilder = (type, allFields=2) => {
|
|
|
+ if (!allFields && type.fields[0].name !== '_id') allFields++
|
|
|
if (allFields)
|
|
|
return '{' +
|
|
|
type.fields.map(field => {
|
|
|
- return field.name + ((field.type.kind === 'OBJECT' && (inTypes(field.type.name)) && projectionBuilder(inTypes(field.type.name), false)) ||
|
|
|
- (field.type.kind === 'LIST' && (inTypes(field.type.ofType.name)) && projectionBuilder(inTypes(field.type.ofType.name), false)) || '')
|
|
|
+ return field.name + ((field.type.kind === 'OBJECT' && (inTypes(field.type.name)) && projectionBuilder(inTypes(field.type.name), allFields -1)) ||
|
|
|
+ (field.type.kind === 'LIST' && (inTypes(field.type.ofType.name)) && projectionBuilder(inTypes(field.type.ofType.name), allFields -1)) || '')
|
|
|
})
|
|
|
.join(',')
|
|
|
+ '}'
|
|
@@ -104,20 +104,30 @@ export default async function createModels2(gql, config={create: 'Upsert', updat
|
|
|
}
|
|
|
|
|
|
const identityMap = {}
|
|
|
+ let identityMapHits = 0
|
|
|
+ let totalObjects = 0
|
|
|
|
|
|
|
|
|
const createClass = (name, type, input) => {
|
|
|
if (!(name in classes)) {
|
|
|
classes[name] = class {
|
|
|
constructor(data={}, empty = false){
|
|
|
- if (data._id && data._id in identityMap)
|
|
|
+ totalObjects ++
|
|
|
+ if (data._id && (data._id in identityMap)){
|
|
|
+ if (identityMap[data._id].empty && !empty){
|
|
|
+ identityMap[data._id].empty = false
|
|
|
+ identityMap[data._id].populate(data)
|
|
|
+ }
|
|
|
+ identityMapHits++
|
|
|
+ console.log(identityMapHits, totalObjects, identityMapHits/totalObjects)
|
|
|
return identityMap[data._id]
|
|
|
+ }
|
|
|
|
|
|
- this.populate(data)
|
|
|
+ if (data._id) identityMap[data._id] = this
|
|
|
|
|
|
this.empty = empty
|
|
|
|
|
|
- if (this._id) identityMap[this._id] = this
|
|
|
+ this.populate(data)
|
|
|
}
|
|
|
|
|
|
populate(data){
|