mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
feat: parse files in parallel at import when multiple (#2372)
cf https://github.com/umap-project/umap/pull/2363#discussion_r1882966275
This commit is contained in:
commit
05c27aed98
3 changed files with 43 additions and 7 deletions
|
@ -526,15 +526,13 @@ export class DataLayer extends ServerStored {
|
||||||
}
|
}
|
||||||
|
|
||||||
async importFromFiles(files, type) {
|
async importFromFiles(files, type) {
|
||||||
let all = []
|
const toLoad = []
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const features = await this.importFromFile(file, type)
|
toLoad.push(this.importFromFile(file, type))
|
||||||
if (features) {
|
|
||||||
all = all.concat(features)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
const features = await Promise.all(toLoad)
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
resolve(all)
|
resolve([].concat(...features))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
umap/tests/fixtures/test_upload_simple_marker.json
vendored
Normal file
19
umap/tests/fixtures/test_upload_simple_marker.json
vendored
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"crs": null,
|
||||||
|
"type": "FeatureCollection",
|
||||||
|
"features": [
|
||||||
|
{
|
||||||
|
"type": "Feature",
|
||||||
|
"geometry": {
|
||||||
|
"coordinates": [
|
||||||
|
-1.09314,
|
||||||
|
50.791718
|
||||||
|
],
|
||||||
|
"type": "Point"
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"name": "Portsmouth"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -9,7 +9,6 @@ from playwright.sync_api import expect
|
||||||
|
|
||||||
from umap.models import DataLayer
|
from umap.models import DataLayer
|
||||||
|
|
||||||
from ..base import mock_tiles
|
|
||||||
from .helpers import save_and_get_json
|
from .helpers import save_and_get_json
|
||||||
|
|
||||||
pytestmark = pytest.mark.django_db
|
pytestmark = pytest.mark.django_db
|
||||||
|
@ -765,3 +764,23 @@ def test_import_georss_from_textarea(tilelayer, live_server, page):
|
||||||
# A layer has been created
|
# A layer has been created
|
||||||
expect(layers).to_have_count(1)
|
expect(layers).to_have_count(1)
|
||||||
expect(markers).to_have_count(1)
|
expect(markers).to_have_count(1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_import_from_multiple_files(live_server, page, tilelayer):
|
||||||
|
page.goto(f"{live_server.url}/map/new/")
|
||||||
|
page.get_by_title("Import data").click()
|
||||||
|
file_input = page.locator("input[type='file']")
|
||||||
|
with page.expect_file_chooser() as fc_info:
|
||||||
|
file_input.click()
|
||||||
|
file_chooser = fc_info.value
|
||||||
|
FIXTURES = Path(__file__).parent.parent / "fixtures"
|
||||||
|
paths = [
|
||||||
|
FIXTURES / "test_upload_data.json",
|
||||||
|
FIXTURES / "test_upload_simple_marker.json",
|
||||||
|
]
|
||||||
|
file_chooser.set_files(paths)
|
||||||
|
markers = page.locator(".leaflet-marker-icon")
|
||||||
|
expect(markers).to_have_count(0)
|
||||||
|
page.get_by_role("button", name="Import data", exact=True).click()
|
||||||
|
# Two in one file, one in the other
|
||||||
|
expect(markers).to_have_count(3)
|
||||||
|
|
Loading…
Reference in a new issue