This repository was archived by the owner on Jun 26, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 181
support large ammount of datasources #1012
Open
adrianmroz-allegro
wants to merge
5
commits into
master
Choose a base branch
from
support-large-ammount-of-datasources
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
40bb5c7
support huge amount of datacubes by adding spliting datacubes from cl…
SingularVlad 7e1a31d
WIP: cubes paging
adrianmroz-allegro 2127f95
Extract pagination utils and add unit tests
adrianmroz-allegro f1f5854
test for fetchDataCubes
adrianmroz-allegro d344d50
unit test for error handling
adrianmroz-allegro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /* | ||
| * Copyright 2017-2022 Allegro.pl | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import axios from "axios"; | ||
| import { expect } from "chai"; | ||
| import * as sinon from "sinon"; | ||
| import { Ajax } from "./ajax"; | ||
|
|
||
| describe("Ajax", () => { | ||
|
|
||
| describe("fetchDataCubes", () => { | ||
| let get: sinon.SinonStub; | ||
|
|
||
| describe("happy path", () => { | ||
| before(() => { | ||
| get = sinon.stub(axios, "get"); | ||
| get.withArgs("sources/dataCubes?page=0") | ||
| .resolves({ data: { dataCubes: ["first-cube", "second-cube"], next: 1 } }); | ||
| get.withArgs("sources/dataCubes?page=1") | ||
| .resolves({ data: { dataCubes: ["third-cube", "fourth-cube"], next: 2 } }); | ||
| get.withArgs("sources/dataCubes?page=2") | ||
| .resolves({ data: { dataCubes: ["fifth-cube", "sixth-cube"], next: 3 } }); | ||
| get.withArgs("sources/dataCubes?page=3") | ||
| .resolves({ data: { dataCubes: ["last-cube"] } }); | ||
| }); | ||
|
|
||
| it("should fetch all data cubes across pages", async () => { | ||
| const dataCubes = await Ajax.fetchDataCubes({}); | ||
| expect(dataCubes).to.be.deep.equal([ | ||
| "first-cube", | ||
| "second-cube", | ||
| "third-cube", | ||
| "fourth-cube", | ||
| "fifth-cube", | ||
| "sixth-cube", | ||
| "last-cube" | ||
| ]); | ||
| }); | ||
|
|
||
| after(() => { | ||
| get.restore(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("error handling", () => { | ||
| before(() => { | ||
| get = sinon.stub(axios, "get"); | ||
| get.withArgs("sources/dataCubes?page=0") | ||
| .resolves({ data: { dataCubes: ["first-cube", "second-cube"], next: 1 } }); | ||
| get.withArgs("sources/dataCubes?page=1") | ||
| .rejects(new Error("Couldn't fetch")); | ||
| }); | ||
|
|
||
| /* | ||
| NOTE: | ||
| Couldn't write this test with any fancy helpers. | ||
| If you try to refactor it, please check if your solution isn't a false positive! | ||
| */ | ||
| it("should rethrow network error", async () => { | ||
| let error; | ||
| try { | ||
| await Ajax.fetchDataCubes({}); | ||
| } catch (e) { | ||
| error = e; | ||
| } | ||
| expect(error).to.have.property("message", "Couldn't fetch"); | ||
| }); | ||
|
|
||
| after(() => { | ||
| get.restore(); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * Copyright 2017-2022 Allegro.pl | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { expect } from "chai"; | ||
| import { serialize, SerializedDataCube } from "../../../common/models/data-cube/data-cube"; | ||
| import { twitterDataCube } from "../../../common/models/data-cube/data-cube.fixtures"; | ||
| import { getDataCubesPage, getPageNumber } from "./pagination"; | ||
|
|
||
| const DATA_CUBE: SerializedDataCube = serialize(twitterDataCube); | ||
|
|
||
| const nCubes = (n: number) => Array.from({ length: n }).map(() => DATA_CUBE); | ||
|
|
||
| describe("DataCube Pagination", () => { | ||
| describe("getPageNumber", () => { | ||
| it("should parse string", () => { | ||
| expect(getPageNumber("10")).to.be.equal(10); | ||
| }); | ||
|
|
||
| it("should return default 0 if empty", () => { | ||
| expect(getPageNumber(undefined)).to.be.equal(0); | ||
| }); | ||
|
|
||
| describe("URLSearchQuery types", () => { | ||
| it("should return default 0 if passed an array", () => { | ||
| expect(getPageNumber(["foobar", "bazz"])).to.be.equal(0); | ||
| }); | ||
|
|
||
| it("should return default 0 if passed an object", () => { | ||
| expect(getPageNumber({ foobar: 42 })).to.be.equal(0); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("getDataCubesPage", () => { | ||
| describe("DataCubes fit into first page", () => { | ||
| const cubes = nCubes(50); | ||
|
|
||
| it("should return all data cubes", () => { | ||
| expect(getDataCubesPage(cubes, 0).dataCubes).to.have.length(50); | ||
| }); | ||
|
|
||
| it("should return empty next page", () => { | ||
| expect(getDataCubesPage(cubes, 0).next).to.be.undefined; | ||
| }); | ||
| }); | ||
|
|
||
| describe("DataCubes does not fit into first page", () => { | ||
| const cubes = nCubes(1500); | ||
|
|
||
| describe("first page", () => { | ||
| it("should return first thousand data cubes", () => { | ||
| expect(getDataCubesPage(cubes, 0).dataCubes).to.have.length(1000); | ||
| }); | ||
|
|
||
| it("should return index of next page", () => { | ||
| expect(getDataCubesPage(cubes, 0).next).to.be.equal(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe("second page", () => { | ||
| it("should return first thousand data cubes", () => { | ||
| expect(getDataCubesPage(cubes, 1).dataCubes).to.have.length(500); | ||
| }); | ||
|
|
||
| it("should return empty next page", () => { | ||
| expect(getDataCubesPage(cubes, 1).next).to.be.undefined; | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * Copyright 2017-2022 Allegro.pl | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { SerializedDataCube } from "../../../common/models/data-cube/data-cube"; | ||
|
|
||
| const PAGE_SIZE = 1000; | ||
|
|
||
| interface DataCubesSlice { | ||
| dataCubes: SerializedDataCube[]; | ||
| next?: number; | ||
| } | ||
|
|
||
| export function getDataCubesPage(dataCubes: SerializedDataCube[], page: number): DataCubesSlice { | ||
| const sliceStart = page * PAGE_SIZE; | ||
| const sliceEnd = sliceStart + PAGE_SIZE; | ||
| const next = sliceEnd < dataCubes.length ? page + 1 : undefined; | ||
| return { | ||
| dataCubes: dataCubes.slice(sliceStart, sliceEnd), | ||
| next | ||
| }; | ||
| } | ||
|
|
||
| export function getPageNumber(page: unknown): number { | ||
| if (typeof page === "string") return parseInt(page, 10); | ||
| return 0; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.