Skip to content

Commit c0b45c1

Browse files
namest504jloleysens
andcommitted
Fix default perPage option (#239073)
## Summary FIX: #238789 ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [ ] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ... --------- Signed-off-by: namest504 <namest504@gmail.com> Co-authored-by: Jean-Louis Leysens <jeanlouis.leysens@elastic.co> (cherry picked from commit 97d93ce)
1 parent 1a3f520 commit c0b45c1

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

src/core/packages/saved-objects/api-server-internal/src/lib/point_in_time_finder.test.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
import { loggerMock, type MockedLogger } from '@kbn/logging-mocks';
1111
import type {
12-
SavedObjectsFindResult,
1312
SavedObjectsCreatePointInTimeFinderOptions,
13+
SavedObjectsFindResult,
1414
} from '@kbn/core-saved-objects-api-server';
1515
import { savedObjectsPointInTimeFinderMock } from '../mocks';
1616

@@ -352,6 +352,7 @@ describe('createPointInTimeFinder()', () => {
352352
sortField: 'updated_at',
353353
sortOrder: 'desc',
354354
type: ['visualization'],
355+
perPage: 1000,
355356
}),
356357
internalOptions
357358
);
@@ -516,5 +517,40 @@ describe('createPointInTimeFinder()', () => {
516517
expect(repository.find).toHaveBeenCalledTimes(2);
517518
expect(repository.closePointInTime).toHaveBeenCalledTimes(2);
518519
});
520+
521+
test('applies defaults as expected', async () => {
522+
repository.openPointInTimeForType.mockResolvedValueOnce({
523+
id: 'abc123',
524+
});
525+
repository.find.mockResolvedValueOnce({
526+
total: 2,
527+
saved_objects: mockHits,
528+
pit_id: 'abc123',
529+
per_page: 2,
530+
page: 0,
531+
});
532+
533+
const findOptions: SavedObjectsCreatePointInTimeFinderOptions = {
534+
type: ['visualization'],
535+
search: 'foo*',
536+
};
537+
538+
const finder = new PointInTimeFinder(findOptions, {
539+
logger,
540+
client: repository,
541+
});
542+
await finder.find().next();
543+
544+
expect(repository.find).toHaveBeenCalledWith(
545+
expect.objectContaining({
546+
pit: expect.objectContaining({ id: 'abc123', keepAlive: '2m' }),
547+
sortField: 'updated_at',
548+
sortOrder: 'desc',
549+
type: ['visualization'],
550+
perPage: 1000,
551+
}),
552+
undefined
553+
);
554+
});
519555
});
520556
});

src/core/packages/saved-objects/api-server-internal/src/lib/point_in_time_finder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class PointInTimeFinder<T = unknown, A = unknown>
4545
{
4646
readonly #log: Logger;
4747
readonly #client: SavedObjectsPointInTimeFinderClient;
48-
readonly #findOptions: SavedObjectsFindOptions;
48+
readonly #findOptions: SavedObjectsFindOptions & { perPage: number };
4949
readonly #internalOptions: SavedObjectsFindInternalOptions | undefined;
5050
#open: boolean = false;
5151
#pitId?: string;
@@ -91,7 +91,7 @@ export class PointInTimeFinder<T = unknown, A = unknown>
9191
this.#log.debug(`Collected [${lastResultsCount}] saved objects`);
9292

9393
// Close PIT if this was our last page
94-
if (this.#pitId && lastResultsCount < this.#findOptions.perPage!) {
94+
if (this.#pitId && lastResultsCount < this.#findOptions.perPage) {
9595
await this.close();
9696
}
9797

@@ -103,7 +103,7 @@ export class PointInTimeFinder<T = unknown, A = unknown>
103103

104104
// We've reached the end when there are fewer hits than our perPage size,
105105
// or when `close()` has been called.
106-
} while (this.#open && lastResultsCount >= this.#findOptions.perPage!);
106+
} while (this.#open && lastResultsCount >= this.#findOptions.perPage);
107107

108108
return;
109109
}

0 commit comments

Comments
 (0)