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

Draft: Caching issue when running source & target env snapshots in parallel #383

Merged
merged 2 commits into from
Jun 29, 2022
Merged
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
40 changes: 26 additions & 14 deletions packages/mdctl-api-driver/lib/cortex.object.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,42 @@ const { privatesAccessor } = require('@medable/mdctl-core-utils/privates'),
PatchManyOperation,
BulkOperation
} = require('./operations'),
{ QueryCursor, AggregationCursor } = require('./cursor'),
registeredObjects = {},
registeredAliases = {}
{ QueryCursor, AggregationCursor } = require('./cursor')


class CortexObject {

constructor(objectName, driver) {

Object.defineProperty(this, 'name', {
value: objectName.toLowerCase(),
enumerable: true
Object.defineProperties(this, {
name: {
value: objectName.toLowerCase(),
enumerable: true
},
registeredObjects: {
value: {}
},
registeredAliases: {
value: {}
}
})

Object.assign(privatesAccessor(this), {
driver: driver || new Driver()
})
}

static registerObject(name, cls, ...aliases) {

registerObject(name, cls, ...aliases) {
[name, ...aliases].map(n => n.toLowerCase()).forEach((alias) => {
registeredAliases[alias] = name
this.registeredAliases[alias] = name
})
registeredObjects[name] = cls
this.registeredObjects[name] = cls
}


// eslint-disable-next-line camelcase
static register_object(...args) {
register_object(...args) {
this.registerObject(...args)
}

Expand All @@ -62,10 +71,12 @@ class CortexObject {
plural = name
}

regName = registeredAliases[singular] // eslint-disable-line prefer-const
if (this.registeredAliases) {
regName = this.registeredAliases[singular] // eslint-disable-line prefer-const
}

if (regName) {
const obj = registeredObjects[regName]
const obj = this.registeredObjects[regName]
obj.driver = driver
return obj
}
Expand All @@ -77,7 +88,7 @@ class CortexObject {

{
const cls = new CortexObject(singular, driver)
this.register_object(singular, cls, plural)
cls.register_object(singular, cls, plural)
return cls
}

Expand Down Expand Up @@ -162,7 +173,8 @@ class Org extends CortexObject {
if (target[property]) {
return target[property]
}
target[property] = CortexObject.as(property, driver) // eslint-disable-line no-param-reassign
// eslint-disable-next-line no-param-reassign
target[property] = CortexObject.as(property, driver)
return target[property]
}
})
Expand Down