Skip to content

Commit bf7a206

Browse files
authored
Merge pull request #253 from DestinyItemManager/batched
Consolidate update validation
2 parents ef22846 + cb7db6a commit bf7a206

17 files changed

+707
-723
lines changed

api/routes/update.ts

Lines changed: 218 additions & 355 deletions
Large diffs are not rendered by default.

api/stately/bulk-queries.test.ts

Lines changed: 69 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { SearchType } from '../shapes/search.js';
22
import { deleteAllDataForUser, exportDataForUser } from './bulk-queries.js';
3+
import { client } from './client.js';
34
import { getItemAnnotationsForProfile, updateItemAnnotation } from './item-annotations-queries.js';
45
import { getItemHashTagsForProfile, updateItemHashTag } from './item-hash-tags-queries.js';
56
import { getLoadoutsForProfile, updateLoadout } from './loadouts-queries.js';
67
import { loadout } from './loadouts-queries.test.js';
7-
import { getSearchesForProfile, updateUsedSearch } from './searches-queries.js';
8+
import { getSearchesForProfile, updateSearches } from './searches-queries.js';
89
import { getSettings, setSetting } from './settings-queries.js';
9-
import { getTrackedTriumphsForProfile, trackTriumph } from './triumphs-queries.js';
10+
import { getTrackedTriumphsForProfile, trackUntrackTriumphs } from './triumphs-queries.js';
1011

1112
const platformMembershipId = '213512057';
1213
const bungieMembershipId = 4321;
@@ -15,27 +16,39 @@ beforeEach(async () => deleteAllDataForUser(bungieMembershipId, [platformMembers
1516

1617
describe('deleteAllDataForUser', () => {
1718
it('should delete all kinds of data', async () => {
18-
await updateItemAnnotation(platformMembershipId, 2, {
19-
id: '123456',
20-
tag: 'favorite',
21-
notes: 'the best',
22-
});
23-
await updateItemAnnotation(platformMembershipId, 1, {
24-
id: '1234567',
25-
tag: 'favorite',
26-
notes: 'the best??',
27-
});
28-
await updateItemHashTag(platformMembershipId, {
29-
hash: 2926662838,
30-
tag: 'favorite',
31-
notes: 'the best',
32-
});
33-
await updateLoadout(platformMembershipId, 2, loadout);
34-
await updateUsedSearch(platformMembershipId, 1, 'is:handcannon', SearchType.Item);
35-
await updateUsedSearch(platformMembershipId, 2, 'tag:junk', SearchType.Item);
36-
await trackTriumph(platformMembershipId, 3851137658);
37-
await setSetting(bungieMembershipId, {
38-
showNewItems: true,
19+
await client.transaction(async (txn) => {
20+
await updateItemAnnotation(txn, platformMembershipId, 2, [
21+
{
22+
id: '123456',
23+
tag: 'favorite',
24+
notes: 'the best',
25+
},
26+
]);
27+
await updateItemAnnotation(txn, platformMembershipId, 1, [
28+
{
29+
id: '1234567',
30+
tag: 'favorite',
31+
notes: 'the best??',
32+
},
33+
]);
34+
await updateItemHashTag(txn, platformMembershipId, {
35+
hash: 2926662838,
36+
tag: 'favorite',
37+
notes: 'the best',
38+
});
39+
await updateLoadout(txn, platformMembershipId, 2, [loadout]);
40+
await updateSearches(txn, platformMembershipId, 1, [
41+
{ query: 'is:handcannon', type: SearchType.Item, incrementUsed: 1, saved: false },
42+
]);
43+
await updateSearches(txn, platformMembershipId, 2, [
44+
{ query: 'tag:junk', type: SearchType.Item, incrementUsed: 1, saved: false },
45+
]);
46+
await trackUntrackTriumphs(txn, platformMembershipId, [
47+
{ recordHash: 3851137658, tracked: true },
48+
]);
49+
await setSetting(txn, bungieMembershipId, {
50+
showNewItems: true,
51+
});
3952
});
4053

4154
await deleteAllDataForUser(bungieMembershipId, [platformMembershipId]);
@@ -57,27 +70,39 @@ describe('deleteAllDataForUser', () => {
5770

5871
describe('exportDataForUser', () => {
5972
it('should delete all kinds of data', async () => {
60-
await updateItemAnnotation(platformMembershipId, 2, {
61-
id: '123456',
62-
tag: 'favorite',
63-
notes: 'the best',
64-
});
65-
await updateItemAnnotation(platformMembershipId, 1, {
66-
id: '1234567',
67-
tag: 'favorite',
68-
notes: 'the best??',
69-
});
70-
await updateItemHashTag(platformMembershipId, {
71-
hash: 2926662838,
72-
tag: 'favorite',
73-
notes: 'the best',
74-
});
75-
await updateLoadout(platformMembershipId, 2, loadout);
76-
await updateUsedSearch(platformMembershipId, 1, 'is:handcannon', SearchType.Item);
77-
await updateUsedSearch(platformMembershipId, 2, 'tag:junk', SearchType.Item);
78-
await trackTriumph(platformMembershipId, 3851137658);
79-
await setSetting(bungieMembershipId, {
80-
showNewItems: true,
73+
await client.transaction(async (txn) => {
74+
await updateItemAnnotation(txn, platformMembershipId, 2, [
75+
{
76+
id: '123456',
77+
tag: 'favorite',
78+
notes: 'the best',
79+
},
80+
]);
81+
await updateItemAnnotation(txn, platformMembershipId, 1, [
82+
{
83+
id: '1234567',
84+
tag: 'favorite',
85+
notes: 'the best??',
86+
},
87+
]);
88+
await updateItemHashTag(txn, platformMembershipId, {
89+
hash: 2926662838,
90+
tag: 'favorite',
91+
notes: 'the best',
92+
});
93+
await updateLoadout(txn, platformMembershipId, 2, [loadout]);
94+
await updateSearches(txn, platformMembershipId, 1, [
95+
{ query: 'is:handcannon', type: SearchType.Item, incrementUsed: 1, saved: false },
96+
]);
97+
await updateSearches(txn, platformMembershipId, 2, [
98+
{ query: 'tag:junk', type: SearchType.Item, incrementUsed: 1, saved: false },
99+
]);
100+
await trackUntrackTriumphs(txn, platformMembershipId, [
101+
{ recordHash: 3851137658, tracked: true },
102+
]);
103+
await setSetting(txn, bungieMembershipId, {
104+
showNewItems: true,
105+
});
81106
});
82107

83108
const exportResponse = await exportDataForUser(bungieMembershipId, [platformMembershipId]);
Lines changed: 74 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { client } from './client.js';
12
import {
23
deleteAllItemAnnotations,
34
deleteItemAnnotation,
@@ -10,10 +11,14 @@ const platformMembershipId = '213512057';
1011
beforeEach(async () => deleteAllItemAnnotations(platformMembershipId));
1112

1213
it('can insert tags where none exist before', async () => {
13-
await updateItemAnnotation(platformMembershipId, 2, {
14-
id: '123456',
15-
tag: 'favorite',
16-
notes: 'the best',
14+
await client.transaction(async (txn) => {
15+
await updateItemAnnotation(txn, platformMembershipId, 2, [
16+
{
17+
id: '123456',
18+
tag: 'favorite',
19+
notes: 'the best',
20+
},
21+
]);
1722
});
1823

1924
const annotations = await getItemAnnotationsForProfile(platformMembershipId, 2);
@@ -25,16 +30,19 @@ it('can insert tags where none exist before', async () => {
2530
});
2631

2732
it('can update tags where none exist before', async () => {
28-
await updateItemAnnotation(platformMembershipId, 2, {
29-
id: '123456',
30-
tag: 'favorite',
31-
notes: 'the best',
32-
});
33-
34-
await updateItemAnnotation(platformMembershipId, 2, {
35-
id: '123456',
36-
tag: 'junk',
37-
notes: 'the worst',
33+
await client.transaction(async (txn) => {
34+
await updateItemAnnotation(txn, platformMembershipId, 2, [
35+
{
36+
id: '123456',
37+
tag: 'favorite',
38+
notes: 'the best',
39+
},
40+
{
41+
id: '123456',
42+
tag: 'junk',
43+
notes: 'the worst',
44+
},
45+
]);
3846
});
3947

4048
const annotations = await getItemAnnotationsForProfile(platformMembershipId, 2);
@@ -46,15 +54,22 @@ it('can update tags where none exist before', async () => {
4654
});
4755

4856
it('can update tags clearing value', async () => {
49-
await updateItemAnnotation(platformMembershipId, 2, {
50-
id: '123456',
51-
tag: 'favorite',
52-
notes: 'the best',
57+
await client.transaction(async (txn) => {
58+
await updateItemAnnotation(txn, platformMembershipId, 2, [
59+
{
60+
id: '123456',
61+
tag: 'favorite',
62+
notes: 'the best',
63+
},
64+
]);
5365
});
54-
55-
await updateItemAnnotation(platformMembershipId, 2, {
56-
id: '123456',
57-
tag: null,
66+
await client.transaction(async (txn) => {
67+
await updateItemAnnotation(txn, platformMembershipId, 2, [
68+
{
69+
id: '123456',
70+
tag: null,
71+
},
72+
]);
5873
});
5974

6075
const annotations = await getItemAnnotationsForProfile(platformMembershipId, 2);
@@ -65,49 +80,61 @@ it('can update tags clearing value', async () => {
6580
});
6681

6782
it('can delete tags', async () => {
68-
await updateItemAnnotation(platformMembershipId, 2, {
69-
id: '123456',
70-
tag: 'favorite',
71-
notes: 'the best',
83+
await client.transaction(async (txn) => {
84+
await updateItemAnnotation(txn, platformMembershipId, 2, [
85+
{
86+
id: '123456',
87+
tag: 'favorite',
88+
notes: 'the best',
89+
},
90+
]);
91+
});
92+
await client.transaction(async (txn) => {
93+
await deleteItemAnnotation(txn, platformMembershipId, 2, ['123456']);
7294
});
73-
74-
await deleteItemAnnotation(platformMembershipId, 2, '123456');
7595

7696
const annotations = await getItemAnnotationsForProfile(platformMembershipId, 2);
7797
expect(annotations).toEqual([]);
7898
});
7999

80100
it('can delete tags by setting both values to null/empty', async () => {
81-
await updateItemAnnotation(platformMembershipId, 2, {
82-
id: '123456',
83-
tag: 'favorite',
84-
notes: 'the best',
101+
await client.transaction(async (txn) => {
102+
await updateItemAnnotation(txn, platformMembershipId, 2, [
103+
{
104+
id: '123456',
105+
tag: 'favorite',
106+
notes: 'the best',
107+
},
108+
]);
85109
});
86-
87-
await updateItemAnnotation(platformMembershipId, 2, {
88-
id: '123456',
89-
tag: null,
90-
notes: '',
110+
await client.transaction(async (txn) => {
111+
await updateItemAnnotation(txn, platformMembershipId, 2, [
112+
{
113+
id: '123456',
114+
tag: null,
115+
notes: '',
116+
},
117+
]);
91118
});
92119

93120
const annotations = await getItemAnnotationsForProfile(platformMembershipId, 2);
94121
expect(annotations).toEqual([]);
95122
});
96123

97124
it('can clear tags', async () => {
98-
await updateItemAnnotation(platformMembershipId, 2, {
99-
id: '123456',
100-
tag: 'favorite',
101-
notes: 'the best',
125+
await client.transaction(async (txn) => {
126+
await updateItemAnnotation(txn, platformMembershipId, 2, [
127+
{
128+
id: '123456',
129+
tag: 'favorite',
130+
notes: 'the best',
131+
},
132+
]);
102133
});
103-
await updateItemAnnotation(platformMembershipId, 2, {
104-
id: '654321',
105-
tag: 'junk',
106-
notes: 'the worst',
134+
await client.transaction(async (txn) => {
135+
await deleteItemAnnotation(txn, platformMembershipId, 2, ['123456', '654321']);
107136
});
108137

109-
await deleteItemAnnotation(platformMembershipId, 2, '123456', '654321');
110-
111138
const annotations = await getItemAnnotationsForProfile(platformMembershipId, 2);
112139
expect(annotations).toEqual([]);
113140
});

0 commit comments

Comments
 (0)