Skip to content

Commit

Permalink
feat(infra): opti indexer performance (#8557)
Browse files Browse the repository at this point in the history
  • Loading branch information
EYHN committed Oct 22, 2024
1 parent d482e2f commit 6ecdc8d
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 222 deletions.
192 changes: 99 additions & 93 deletions packages/common/infra/src/sync/indexer/__tests__/black-box.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,101 +454,107 @@ describe.each([
});
});

test('subscribe', async () => {
await writeData({
'1': {
title: 'hello world',
},
});

let value = null as any;
index
.search$({
type: 'match',
field: 'title',
match: 'hello world',
})
.pipe(map(v => (value = v)))
.subscribe();

await vitest.waitFor(
() => {
expect(value).toEqual({
nodes: [
{
id: '1',
score: expect.anything(),
test(
'subscribe',
{
timeout: 30000,
},
async () => {
await writeData({
'1': {
title: 'hello world',
},
});

let value = null as any;
index
.search$({
type: 'match',
field: 'title',
match: 'hello world',
})
.pipe(map(v => (value = v)))
.subscribe();

await vitest.waitFor(
() => {
expect(value).toEqual({
nodes: [
{
id: '1',
score: expect.anything(),
},
],
pagination: {
count: 1,
hasMore: false,
limit: expect.anything(),
skip: 0,
},
],
pagination: {
count: 1,
hasMore: false,
limit: expect.anything(),
skip: 0,
},
});
},
{
timeout: 5000,
}
);

await writeData({
'2': {
title: 'hello world',
},
});
});
},
{
timeout: 10000,
}
);

await vitest.waitFor(
() => {
expect(value).toEqual({
nodes: [
{
id: '1',
score: expect.anything(),
},
{
id: '2',
score: expect.anything(),
await writeData({
'2': {
title: 'hello world',
},
});

await vitest.waitFor(
() => {
expect(value).toEqual({
nodes: [
{
id: '1',
score: expect.anything(),
},
{
id: '2',
score: expect.anything(),
},
],
pagination: {
count: 2,
hasMore: false,
limit: expect.anything(),
skip: 0,
},
],
pagination: {
count: 2,
hasMore: false,
limit: expect.anything(),
skip: 0,
},
});
},
{
timeout: 5000,
}
);

const writer = await index.write();
writer.delete('1');
await writer.commit();

await vitest.waitFor(
() => {
expect(value).toEqual({
nodes: [
{
id: '2',
score: expect.anything(),
});
},
{
timeout: 10000,
}
);

const writer = await index.write();
writer.delete('1');
await writer.commit();

await vitest.waitFor(
() => {
expect(value).toEqual({
nodes: [
{
id: '2',
score: expect.anything(),
},
],
pagination: {
count: 1,
hasMore: false,
limit: expect.anything(),
skip: 0,
},
],
pagination: {
count: 1,
hasMore: false,
limit: expect.anything(),
skip: 0,
},
});
},
{
timeout: 5000,
}
);
});
});
},
{
timeout: 10000,
}
);
}
);
});
Loading

0 comments on commit 6ecdc8d

Please sign in to comment.