feat: parse files in parallel at import when multiple (#2372)
Some checks are pending
Test & Docs / tests (postgresql, 3.10) (push) Waiting to run
Test & Docs / tests (postgresql, 3.12) (push) Waiting to run
Test & Docs / lint (push) Waiting to run
Test & Docs / docs (push) Waiting to run

cf https://github.com/umap-project/umap/pull/2363#discussion_r1882966275
This commit is contained in:
Yohan Boniface 2024-12-16 21:36:42 +01:00 committed by GitHub
commit 05c27aed98
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 43 additions and 7 deletions

View file

@ -526,15 +526,13 @@ export class DataLayer extends ServerStored {
}
async importFromFiles(files, type) {
let all = []
const toLoad = []
for (const file of files) {
const features = await this.importFromFile(file, type)
if (features) {
all = all.concat(features)
}
toLoad.push(this.importFromFile(file, type))
}
const features = await Promise.all(toLoad)
return new Promise((resolve) => {
resolve(all)
resolve([].concat(...features))
})
}

View file

@ -0,0 +1,19 @@
{
"crs": null,
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"coordinates": [
-1.09314,
50.791718
],
"type": "Point"
},
"properties": {
"name": "Portsmouth"
}
}
]
}

View file

@ -9,7 +9,6 @@ from playwright.sync_api import expect
from umap.models import DataLayer
from ..base import mock_tiles
from .helpers import save_and_get_json
pytestmark = pytest.mark.django_db
@ -765,3 +764,23 @@ def test_import_georss_from_textarea(tilelayer, live_server, page):
# A layer has been created
expect(layers).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)