Skip to content

Commit bfd5de0

Browse files
committed
feat: add flexSearchPerformanceParams to @rootEntity
These params allow to configure arangosearch parameters that might need tweaking from case to case.
1 parent 51d83f9 commit bfd5de0

File tree

8 files changed

+505
-14
lines changed

8 files changed

+505
-14
lines changed

spec/database/arangodb/arangodb-adapter.spec.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ArangoDBAdapter } from '../../../src/database/arangodb';
44
import { createSimpleModel } from '../../model/model-spec.helper';
55
import { createTempDatabase, getTempDatabase } from '../../regression/initialization';
66
import { isArangoDBDisabled } from './arangodb-test-utils';
7+
import { ArangoSearchViewProperties } from 'arangojs/view';
78

89
describe('ArangoDBAdapter', () => {
910
describe('updateSchema', () => {
@@ -151,5 +152,61 @@ describe('ArangoDBAdapter', () => {
151152
},
152153
]);
153154
});
155+
156+
it('it resets arangosearch view parameters to configured values', async function () {
157+
// can't use arrow function because we need the "this"
158+
if (isArangoDBDisabled()) {
159+
(this as any).skip();
160+
return;
161+
}
162+
163+
const model = createSimpleModel(gql`
164+
type Delivery
165+
@rootEntity(
166+
flexSearch: true
167+
flexSearchPerformanceParams: {
168+
commitIntervalMsec: 2000
169+
consolidationIntervalMsec: 8000
170+
cleanupIntervalStep: 1
171+
}
172+
) {
173+
deliveryNumber: String @key @flexSearch
174+
}
175+
`);
176+
177+
const dbConfig = await createTempDatabase();
178+
const adapter = new ArangoDBAdapter({
179+
...dbConfig,
180+
createIndicesInBackground: true,
181+
});
182+
const db = getTempDatabase();
183+
await adapter.updateSchema(model);
184+
185+
const view = db.view('flex_view_deliveries');
186+
const properties = (await view.properties()) as ArangoSearchViewProperties;
187+
expect(properties.commitIntervalMsec).to.equal(2000);
188+
expect(properties.consolidationIntervalMsec).to.equal(8000);
189+
expect(properties.cleanupIntervalStep).to.equal(1);
190+
191+
await view.updateProperties({
192+
commitIntervalMsec: 12345,
193+
consolidationIntervalMsec: 54321,
194+
cleanupIntervalStep: 7,
195+
});
196+
197+
const updatedProperties = (await view.properties()) as ArangoSearchViewProperties;
198+
expect(updatedProperties.commitIntervalMsec).to.equal(12345);
199+
expect(updatedProperties.consolidationIntervalMsec).to.equal(54321);
200+
expect(updatedProperties.cleanupIntervalStep).to.equal(7);
201+
202+
// running the migrations again should reset it
203+
await adapter.updateSchema(model);
204+
205+
const propertiesAfterSecondMigration =
206+
(await view.properties()) as ArangoSearchViewProperties;
207+
expect(properties.commitIntervalMsec).to.equal(2000);
208+
expect(properties.consolidationIntervalMsec).to.equal(8000);
209+
expect(properties.cleanupIntervalStep).to.equal(1);
210+
});
154211
});
155212
});
Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
import { assertValidatorAcceptsAndDoesNotWarn, assertValidatorRejects } from './helpers';
2+
3+
describe('flexSearchPerformanceParams in @rootEntity', () => {
4+
it('accepts omitting it', () => {
5+
assertValidatorAcceptsAndDoesNotWarn(`
6+
type Stuff @rootEntity(
7+
flexSearch: true
8+
) {
9+
foo: String @flexSearch
10+
}
11+
`);
12+
});
13+
it('accepts it empty', () => {
14+
assertValidatorAcceptsAndDoesNotWarn(`
15+
type Stuff @rootEntity(
16+
flexSearch: true
17+
flexSearchPerformanceParams: {}
18+
) {
19+
foo: String @flexSearch
20+
}
21+
`);
22+
});
23+
24+
describe('commitIntervalMsec', () => {
25+
it('accepts it being null', () => {
26+
assertValidatorAcceptsAndDoesNotWarn(`
27+
type Stuff @rootEntity(
28+
flexSearch: true
29+
flexSearchPerformanceParams: {
30+
commitIntervalMsec: null
31+
}
32+
) {
33+
foo: String @flexSearch
34+
}
35+
`);
36+
});
37+
38+
it('accepts 100', () => {
39+
assertValidatorAcceptsAndDoesNotWarn(`
40+
type Stuff @rootEntity(
41+
flexSearch: true
42+
flexSearchPerformanceParams: {
43+
commitIntervalMsec: 100
44+
}
45+
) {
46+
foo: String @flexSearch
47+
}
48+
`);
49+
});
50+
51+
it('accepts 5000', () => {
52+
assertValidatorAcceptsAndDoesNotWarn(`
53+
type Stuff @rootEntity(
54+
flexSearch: true
55+
flexSearchPerformanceParams: {
56+
commitIntervalMsec: 5000
57+
}
58+
) {
59+
foo: String @flexSearch
60+
}
61+
`);
62+
});
63+
64+
it('rejects 50', () => {
65+
assertValidatorRejects(
66+
`
67+
type Stuff @rootEntity(
68+
flexSearch: true
69+
flexSearchPerformanceParams: {
70+
commitIntervalMsec: 50
71+
}
72+
) {
73+
foo: String @flexSearch
74+
}
75+
`,
76+
'Cannot be less than 100.',
77+
);
78+
});
79+
80+
it('rejects -1', () => {
81+
assertValidatorRejects(
82+
`
83+
type Stuff @rootEntity(
84+
flexSearch: true
85+
flexSearchPerformanceParams: {
86+
commitIntervalMsec: -1
87+
}
88+
) {
89+
foo: String @flexSearch
90+
}
91+
`,
92+
'Cannot be less than 100.',
93+
);
94+
});
95+
96+
it('rejects 123.4', () => {
97+
assertValidatorRejects(
98+
`
99+
type Stuff @rootEntity(
100+
flexSearch: true
101+
flexSearchPerformanceParams: {
102+
commitIntervalMsec: 123.4
103+
}
104+
) {
105+
foo: String @flexSearch
106+
}
107+
`,
108+
'Int cannot represent non-integer value: 123.4',
109+
);
110+
});
111+
});
112+
113+
describe('consolidationIntervalMsec', () => {
114+
it('accepts it being null', () => {
115+
assertValidatorAcceptsAndDoesNotWarn(`
116+
type Stuff @rootEntity(
117+
flexSearch: true
118+
flexSearchPerformanceParams: {
119+
consolidationIntervalMsec: null
120+
}
121+
) {
122+
foo: String @flexSearch
123+
}
124+
`);
125+
});
126+
127+
it('accepts 100', () => {
128+
assertValidatorAcceptsAndDoesNotWarn(`
129+
type Stuff @rootEntity(
130+
flexSearch: true
131+
flexSearchPerformanceParams: {
132+
consolidationIntervalMsec: 100
133+
}
134+
) {
135+
foo: String @flexSearch
136+
}
137+
`);
138+
});
139+
140+
it('accepts 5000', () => {
141+
assertValidatorAcceptsAndDoesNotWarn(`
142+
type Stuff @rootEntity(
143+
flexSearch: true
144+
flexSearchPerformanceParams: {
145+
consolidationIntervalMsec: 5000
146+
}
147+
) {
148+
foo: String @flexSearch
149+
}
150+
`);
151+
});
152+
153+
it('rejects 50', () => {
154+
assertValidatorRejects(
155+
`
156+
type Stuff @rootEntity(
157+
flexSearch: true
158+
flexSearchPerformanceParams: {
159+
consolidationIntervalMsec: 50
160+
}
161+
) {
162+
foo: String @flexSearch
163+
}
164+
`,
165+
'Cannot be less than 100.',
166+
);
167+
});
168+
169+
it('rejects -1', () => {
170+
assertValidatorRejects(
171+
`
172+
type Stuff @rootEntity(
173+
flexSearch: true
174+
flexSearchPerformanceParams: {
175+
consolidationIntervalMsec: -1
176+
}
177+
) {
178+
foo: String @flexSearch
179+
}
180+
`,
181+
'Cannot be less than 100.',
182+
);
183+
});
184+
185+
it('rejects 123.4', () => {
186+
assertValidatorRejects(
187+
`
188+
type Stuff @rootEntity(
189+
flexSearch: true
190+
flexSearchPerformanceParams: {
191+
consolidationIntervalMsec: 123.4
192+
}
193+
) {
194+
foo: String @flexSearch
195+
}
196+
`,
197+
'Int cannot represent non-integer value: 123.4',
198+
);
199+
});
200+
});
201+
202+
describe('cleanupIntervalStep', () => {
203+
it('accepts it being null', () => {
204+
assertValidatorAcceptsAndDoesNotWarn(`
205+
type Stuff @rootEntity(
206+
flexSearch: true
207+
flexSearchPerformanceParams: {
208+
cleanupIntervalStep: null
209+
}
210+
) {
211+
foo: String @flexSearch
212+
}
213+
`);
214+
});
215+
216+
it('accepts 0', () => {
217+
assertValidatorAcceptsAndDoesNotWarn(`
218+
type Stuff @rootEntity(
219+
flexSearch: true
220+
flexSearchPerformanceParams: {
221+
cleanupIntervalStep: 0
222+
}
223+
) {
224+
foo: String @flexSearch
225+
}
226+
`);
227+
});
228+
229+
it('accepts 5', () => {
230+
assertValidatorAcceptsAndDoesNotWarn(`
231+
type Stuff @rootEntity(
232+
flexSearch: true
233+
flexSearchPerformanceParams: {
234+
cleanupIntervalStep: 5
235+
}
236+
) {
237+
foo: String @flexSearch
238+
}
239+
`);
240+
});
241+
242+
it('rejects -1', () => {
243+
assertValidatorRejects(
244+
`
245+
type Stuff @rootEntity(
246+
flexSearch: true
247+
flexSearchPerformanceParams: {
248+
cleanupIntervalStep: -1
249+
}
250+
) {
251+
foo: String @flexSearch
252+
}
253+
`,
254+
'Cannot be negative.',
255+
);
256+
});
257+
258+
it('rejects 123.4', () => {
259+
assertValidatorRejects(
260+
`
261+
type Stuff @rootEntity(
262+
flexSearch: true
263+
flexSearchPerformanceParams: {
264+
cleanupIntervalStep: 123.4
265+
}
266+
) {
267+
foo: String @flexSearch
268+
}
269+
`,
270+
'Int cannot represent non-integer value: 123.4',
271+
);
272+
});
273+
});
274+
});

0 commit comments

Comments
 (0)