@naturalcycles/abba 1.18.1 → 1.18.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.
package/dist/abba.js CHANGED
@@ -63,7 +63,11 @@ class Abba {
63
63
  (0, util_1.validateTotalBucketRatio)(buckets);
64
64
  }
65
65
  const updatedExperiment = await this.experimentDao.save(experiment, { saveMethod: 'update' });
66
- const updatedBuckets = await this.bucketDao.saveBatch(buckets.map(b => ({ ...b, experimentId: updatedExperiment.id })));
66
+ const updatedBuckets = await (0, js_lib_1.pMap)(buckets, async (bucket) => {
67
+ // Don't save batch with a single saveMethod because the cascade will delete all user assignments
68
+ const saveMethod = bucket.id ? 'update' : 'insert';
69
+ return await this.bucketDao.save({ ...bucket, experimentId: updatedExperiment.id }, { saveMethod });
70
+ });
67
71
  await this.updateExclusions(updatedExperiment.id, updatedExperiment.exclusions);
68
72
  return {
69
73
  ...updatedExperiment,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/abba",
3
- "version": "1.18.1",
3
+ "version": "1.18.2",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build": "build",
package/src/abba.ts CHANGED
@@ -91,9 +91,14 @@ export class Abba {
91
91
  }
92
92
 
93
93
  const updatedExperiment = await this.experimentDao.save(experiment, { saveMethod: 'update' })
94
- const updatedBuckets = await this.bucketDao.saveBatch(
95
- buckets.map(b => ({ ...b, experimentId: updatedExperiment.id })),
96
- )
94
+ const updatedBuckets = await pMap(buckets, async bucket => {
95
+ // Don't save batch with a single saveMethod because the cascade will delete all user assignments
96
+ const saveMethod = bucket.id ? 'update' : 'insert'
97
+ return await this.bucketDao.save(
98
+ { ...bucket, experimentId: updatedExperiment.id },
99
+ { saveMethod },
100
+ )
101
+ })
97
102
 
98
103
  await this.updateExclusions(updatedExperiment.id, updatedExperiment.exclusions)
99
104