@naturalcycles/abba 1.18.2 → 1.18.4

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
@@ -12,7 +12,7 @@ const util_1 = require("./util");
12
12
  /**
13
13
  * 10 minutes
14
14
  */
15
- const CACHE_TTL = 600000; // 10 minutes
15
+ const CACHE_TTL = 600_000; // 10 minutes
16
16
  class Abba {
17
17
  constructor(cfg) {
18
18
  this.cfg = cfg;
@@ -64,9 +64,7 @@ class Abba {
64
64
  }
65
65
  const updatedExperiment = await this.experimentDao.save(experiment, { saveMethod: 'update' });
66
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 });
67
+ return await this.bucketDao.save({ ...bucket, experimentId: updatedExperiment.id }, { saveMethod: bucket.id ? 'update' : undefined });
70
68
  });
71
69
  await this.updateExclusions(updatedExperiment.id, updatedExperiment.exclusions);
72
70
  return {
@@ -101,6 +99,12 @@ class Abba {
101
99
  * Cold method.
102
100
  */
103
101
  async deleteExperiment(experimentId) {
102
+ const userAssignmentDeleteQuery = this.userAssignmentDao
103
+ .query()
104
+ .filterEq('experimentId', experimentId);
105
+ await this.userAssignmentDao.deleteByQuery(userAssignmentDeleteQuery);
106
+ const bucketDeleteQuery = this.bucketDao.query().filterEq('experimentId', experimentId);
107
+ await this.bucketDao.deleteByQuery(bucketDeleteQuery);
104
108
  await this.experimentDao.deleteById(experimentId);
105
109
  await this.updateExclusions(experimentId, []);
106
110
  }
@@ -236,5 +240,5 @@ class Abba {
236
240
  }
237
241
  exports.Abba = Abba;
238
242
  tslib_1.__decorate([
239
- (0, js_lib_1._AsyncMemo)({ cacheFactory: () => new nodejs_lib_1.LRUMemoCache({ ttl: CACHE_TTL, max: 1 }) })
243
+ (0, js_lib_1._Memo)({ cacheFactory: () => new nodejs_lib_1.LRUMemoCache({ ttl: CACHE_TTL, max: 1 }) })
240
244
  ], Abba.prototype, "getAllExperiments", null);
@@ -42,10 +42,10 @@ CREATE TABLE IF NOT EXISTS `UserAssignment` (
42
42
  ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
43
43
 
44
44
  -- AddForeignKey
45
- ALTER TABLE `Bucket` ADD CONSTRAINT `Bucket_experimentId_fkey` FOREIGN KEY (`experimentId`) REFERENCES `Experiment`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
45
+ ALTER TABLE `Bucket` ADD CONSTRAINT `Bucket_experimentId_fkey` FOREIGN KEY (`experimentId`) REFERENCES `Experiment`(`id`);
46
46
 
47
47
  -- AddForeignKey
48
- ALTER TABLE `UserAssignment` ADD CONSTRAINT `UserAssignment_bucketId_fkey` FOREIGN KEY (`bucketId`) REFERENCES `Bucket`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
48
+ ALTER TABLE `UserAssignment` ADD CONSTRAINT `UserAssignment_bucketId_fkey` FOREIGN KEY (`bucketId`) REFERENCES `Bucket`(`id`);
49
49
 
50
50
  -- AddForeignKey
51
- ALTER TABLE `UserAssignment` ADD CONSTRAINT `UserAssignment_experimentId_fkey` FOREIGN KEY (`experimentId`) REFERENCES `Experiment`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
51
+ ALTER TABLE `UserAssignment` ADD CONSTRAINT `UserAssignment_experimentId_fkey` FOREIGN KEY (`experimentId`) REFERENCES `Experiment`(`id`);
package/package.json CHANGED
@@ -1,10 +1,8 @@
1
1
  {
2
2
  "name": "@naturalcycles/abba",
3
- "version": "1.18.2",
3
+ "version": "1.18.4",
4
4
  "scripts": {
5
- "prepare": "husky install",
6
- "build": "build",
7
- "build-prod": "build-prod"
5
+ "prepare": "husky"
8
6
  },
9
7
  "dependencies": {
10
8
  "@naturalcycles/db-lib": "^9.1.0",
package/src/abba.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { _assert, _AsyncMemo, _shuffle, pMap } from '@naturalcycles/js-lib'
1
+ import { _assert, _Memo, _shuffle, pMap } from '@naturalcycles/js-lib'
2
2
  import { LRUMemoCache } from '@naturalcycles/nodejs-lib'
3
3
  import { bucketDao } from './dao/bucket.dao'
4
4
  import { experimentDao } from './dao/experiment.dao'
@@ -38,7 +38,7 @@ export class Abba {
38
38
  * Returns all experiments.
39
39
  * Cached (see CACHE_TTL)
40
40
  */
41
- @_AsyncMemo({ cacheFactory: () => new LRUMemoCache({ ttl: CACHE_TTL, max: 1 }) })
41
+ @_Memo({ cacheFactory: () => new LRUMemoCache({ ttl: CACHE_TTL, max: 1 }) })
42
42
  async getAllExperiments(): Promise<ExperimentWithBuckets[]> {
43
43
  return await this.getAllExperimentsNoCache()
44
44
  }
@@ -92,11 +92,9 @@ export class Abba {
92
92
 
93
93
  const updatedExperiment = await this.experimentDao.save(experiment, { saveMethod: 'update' })
94
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
95
  return await this.bucketDao.save(
98
96
  { ...bucket, experimentId: updatedExperiment.id },
99
- { saveMethod },
97
+ { saveMethod: bucket.id ? 'update' : undefined },
100
98
  )
101
99
  })
102
100
 
@@ -143,6 +141,14 @@ export class Abba {
143
141
  * Cold method.
144
142
  */
145
143
  async deleteExperiment(experimentId: string): Promise<void> {
144
+ const userAssignmentDeleteQuery = this.userAssignmentDao
145
+ .query()
146
+ .filterEq('experimentId', experimentId)
147
+ await this.userAssignmentDao.deleteByQuery(userAssignmentDeleteQuery)
148
+
149
+ const bucketDeleteQuery = this.bucketDao.query().filterEq('experimentId', experimentId)
150
+ await this.bucketDao.deleteByQuery(bucketDeleteQuery)
151
+
146
152
  await this.experimentDao.deleteById(experimentId)
147
153
  await this.updateExclusions(experimentId, [])
148
154
  }
@@ -42,10 +42,10 @@ CREATE TABLE IF NOT EXISTS `UserAssignment` (
42
42
  ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
43
43
 
44
44
  -- AddForeignKey
45
- ALTER TABLE `Bucket` ADD CONSTRAINT `Bucket_experimentId_fkey` FOREIGN KEY (`experimentId`) REFERENCES `Experiment`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
45
+ ALTER TABLE `Bucket` ADD CONSTRAINT `Bucket_experimentId_fkey` FOREIGN KEY (`experimentId`) REFERENCES `Experiment`(`id`);
46
46
 
47
47
  -- AddForeignKey
48
- ALTER TABLE `UserAssignment` ADD CONSTRAINT `UserAssignment_bucketId_fkey` FOREIGN KEY (`bucketId`) REFERENCES `Bucket`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
48
+ ALTER TABLE `UserAssignment` ADD CONSTRAINT `UserAssignment_bucketId_fkey` FOREIGN KEY (`bucketId`) REFERENCES `Bucket`(`id`);
49
49
 
50
50
  -- AddForeignKey
51
- ALTER TABLE `UserAssignment` ADD CONSTRAINT `UserAssignment_experimentId_fkey` FOREIGN KEY (`experimentId`) REFERENCES `Experiment`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
51
+ ALTER TABLE `UserAssignment` ADD CONSTRAINT `UserAssignment_experimentId_fkey` FOREIGN KEY (`experimentId`) REFERENCES `Experiment`(`id`);
package/src/util.ts CHANGED
@@ -31,7 +31,7 @@ export const generateUserAssignmentData = (
31
31
  userId,
32
32
  experimentId: experiment.id,
33
33
  bucketId: bucket?.id || null,
34
- }
34
+ } as UserAssignment
35
35
  }
36
36
 
37
37
  /**