@autofleet/matmon 2.0.4-beta-1 → 2.0.4-beta-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -21,7 +21,7 @@ const INVALIDATION_HOOKS = ['afterSave', 'afterUpdate', 'afterDestroy'];
|
|
|
21
21
|
const BULK_HOOKS = ['beforeBulkUpdate', 'beforeBulkDestroy'];
|
|
22
22
|
const generateInstanceKey = (name, id) => `${AF_SERVICE_NAME}:${ORM_CACHE_PREFIX}:${name}_${id}`;
|
|
23
23
|
const generateDependencyKey = (modelName, associationName, associationId) => `${AF_SERVICE_NAME}:${ORM_CACHE_PREFIX}:${modelName}_${associationName}_${associationId}_DEPENDENCIES`;
|
|
24
|
-
const getInstanceDependencyKeys = (modelOptions, instance) => newrelic_1.default.startSegment(
|
|
24
|
+
const getInstanceDependencyKeys = (modelOptions, instance) => newrelic_1.default.startSegment(`${ORM_CACHE_PREFIX}:getInstanceDependencyKeys`, true, () => {
|
|
25
25
|
const keys = modelOptions.associations
|
|
26
26
|
.filter((associationOptions) => instance[associationOptions.alias])
|
|
27
27
|
.map((associationOptions) => {
|
|
@@ -46,7 +46,13 @@ const getInstanceDependencyKeys = (modelOptions, instance) => newrelic_1.default
|
|
|
46
46
|
const handleTransactionHook = (instance, options, func) => {
|
|
47
47
|
const { transaction } = options;
|
|
48
48
|
if (transaction) {
|
|
49
|
-
transaction
|
|
49
|
+
if (!transaction[ORM_CACHE_PREFIX]) {
|
|
50
|
+
transaction[ORM_CACHE_PREFIX] = new Set();
|
|
51
|
+
}
|
|
52
|
+
if (!transaction[ORM_CACHE_PREFIX].has(instance.id)) {
|
|
53
|
+
transaction.afterCommit(() => func(instance));
|
|
54
|
+
transaction[ORM_CACHE_PREFIX].add(instance.id);
|
|
55
|
+
}
|
|
50
56
|
}
|
|
51
57
|
else {
|
|
52
58
|
func(instance);
|
|
@@ -61,7 +67,7 @@ class SequelizeAdapter {
|
|
|
61
67
|
return this.ormInstance.models[modelName];
|
|
62
68
|
}
|
|
63
69
|
getModelDependencies(modelName) {
|
|
64
|
-
return newrelic_1.default.startSegment(
|
|
70
|
+
return newrelic_1.default.startSegment(`${ORM_CACHE_PREFIX}:getModelDependencies`, true, () => {
|
|
65
71
|
const { associations } = this.ormInstance.models[modelName];
|
|
66
72
|
return [
|
|
67
73
|
...Object.keys(associations).map(association => {
|
|
@@ -90,7 +96,7 @@ class SequelizeAdapter {
|
|
|
90
96
|
}
|
|
91
97
|
}
|
|
92
98
|
injectGetWithCacheFunction(cache, modelOptions) {
|
|
93
|
-
const addDependencies = (instance) => newrelic_1.default.startSegment(
|
|
99
|
+
const addDependencies = (instance) => newrelic_1.default.startSegment(`${ORM_CACHE_PREFIX}:addDependencies`, true, () => {
|
|
94
100
|
const dependencyKeys = getInstanceDependencyKeys(modelOptions, instance);
|
|
95
101
|
const instanceKey = generateInstanceKey(modelOptions.name, instance.id);
|
|
96
102
|
this.debug('Adding dependencies', { instanceKey, dependencyKeys });
|
|
@@ -120,7 +126,7 @@ class SequelizeAdapter {
|
|
|
120
126
|
});
|
|
121
127
|
}
|
|
122
128
|
addInvalidationHooks(cache, modelOptions) {
|
|
123
|
-
const invalidateModelInstance = (hook, instance) => newrelic_1.default.startSegment(
|
|
129
|
+
const invalidateModelInstance = (hook, instance) => newrelic_1.default.startSegment(`${ORM_CACHE_PREFIX}:invalidateModelInstance`, true, () => {
|
|
124
130
|
const dependencyKeys = getInstanceDependencyKeys(modelOptions, instance);
|
|
125
131
|
const instanceKey = generateInstanceKey(modelOptions.name, instance.id);
|
|
126
132
|
this.debug(`Removing dependencies (triggered by ${hook})`, { instance, instanceKey, dependencyKeys });
|
|
@@ -130,7 +136,7 @@ class SequelizeAdapter {
|
|
|
130
136
|
removeMulti.del(instanceKey);
|
|
131
137
|
return removeMultiAsync();
|
|
132
138
|
});
|
|
133
|
-
const invalidateModelInstanceByAssociation = (hook, association, associationId) => newrelic_1.default.startSegment(
|
|
139
|
+
const invalidateModelInstanceByAssociation = (hook, association, associationId) => newrelic_1.default.startSegment(`${ORM_CACHE_PREFIX}:invalidateModelInstanceByAssociation`, true, () => __awaiter(this, void 0, void 0, function* () {
|
|
134
140
|
const dependentInstancesKeys = yield cache.getClient().smembersAsync(generateDependencyKey(modelOptions.name, association, associationId));
|
|
135
141
|
this.debug(`Invalidating dependent instances (triggered by ${hook})`, { dependentInstancesKeys });
|
|
136
142
|
const removeMulti = cache.getClient().multi();
|