@naturalcycles/abba 1.14.1 → 1.15.1

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.
package/dist/abba.js CHANGED
@@ -62,7 +62,7 @@ class Abba {
62
62
  if (experiment.status === types_1.AssignmentStatus.Active) {
63
63
  (0, util_1.validateTotalBucketRatio)(buckets);
64
64
  }
65
- const updatedExperiment = await this.experimentDao.save(experiment);
65
+ const updatedExperiment = await this.experimentDao.save(experiment, { saveMethod: 'update' });
66
66
  const updatedBuckets = await this.bucketDao.saveBatch(buckets.map(b => ({ ...b, experimentId: experiment.id })));
67
67
  await this.updateExclusions(updatedExperiment.id, updatedExperiment.exclusions);
68
68
  return {
@@ -90,7 +90,7 @@ class Abba {
90
90
  requiresUpdating.push(experiment);
91
91
  }
92
92
  });
93
- await this.experimentDao.saveBatch(requiresUpdating);
93
+ await this.experimentDao.saveBatch(requiresUpdating, { saveMethod: 'update' });
94
94
  }
95
95
  /**
96
96
  * Delete an experiment. Removes all user assignments and buckets.
@@ -11,7 +11,6 @@ const experimentDao = (db) => new ExperimentDao({
11
11
  table: 'Experiment',
12
12
  createId: false,
13
13
  idType: 'number',
14
- assignGeneratedIds: true,
15
14
  hooks: {
16
15
  beforeBMToDBM: bm => ({
17
16
  ...bm,
package/dist/util.js CHANGED
@@ -126,6 +126,10 @@ exports.canGenerateNewAssignments = canGenerateNewAssignments;
126
126
  const getUserExclusionSet = (experiments, existingAssignments) => {
127
127
  const exclusionSet = new Set();
128
128
  existingAssignments.forEach(assignment => {
129
+ // Users who are excluded from an experiment due to sampling
130
+ // should not prevent potential assignment to other mutually exclusive experiments
131
+ if (assignment.bucketId === null)
132
+ return;
129
133
  const experiment = experiments.find(e => e.id === assignment.experimentId);
130
134
  experiment?.exclusions.forEach(experimentId => exclusionSet.add(experimentId));
131
135
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/abba",
3
- "version": "1.14.1",
3
+ "version": "1.15.1",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build": "build",
package/src/abba.ts CHANGED
@@ -92,7 +92,7 @@ export class Abba {
92
92
  validateTotalBucketRatio(buckets)
93
93
  }
94
94
 
95
- const updatedExperiment = await this.experimentDao.save(experiment)
95
+ const updatedExperiment = await this.experimentDao.save(experiment, { saveMethod: 'update' })
96
96
  const updatedBuckets = await this.bucketDao.saveBatch(
97
97
  buckets.map(b => ({ ...b, experimentId: experiment.id })),
98
98
  )
@@ -132,7 +132,7 @@ export class Abba {
132
132
  }
133
133
  })
134
134
 
135
- await this.experimentDao.saveBatch(requiresUpdating)
135
+ await this.experimentDao.saveBatch(requiresUpdating, { saveMethod: 'update' })
136
136
  }
137
137
 
138
138
  /**
@@ -13,9 +13,8 @@ export const experimentDao = (db: CommonDB): ExperimentDao =>
13
13
  new ExperimentDao({
14
14
  db,
15
15
  table: 'Experiment',
16
- createId: false, // mysql auto_increment is used instead
16
+ createId: false, // Always provided on create
17
17
  idType: 'number',
18
- assignGeneratedIds: true,
19
18
  hooks: {
20
19
  beforeBMToDBM: bm => ({
21
20
  ...bm,
package/src/util.ts CHANGED
@@ -150,6 +150,10 @@ export const getUserExclusionSet = (
150
150
  ): ExclusionSet => {
151
151
  const exclusionSet: ExclusionSet = new Set()
152
152
  existingAssignments.forEach(assignment => {
153
+ // Users who are excluded from an experiment due to sampling
154
+ // should not prevent potential assignment to other mutually exclusive experiments
155
+ if (assignment.bucketId === null) return
156
+
153
157
  const experiment = experiments.find(e => e.id === assignment.experimentId)
154
158
  experiment?.exclusions.forEach(experimentId => exclusionSet.add(experimentId))
155
159
  })