perf+feat(import): fix O(n^2) CSV read, smaller batch, progress bar#1836
Open
AllWorkNoPlay-95 wants to merge 5 commits into
Open
perf+feat(import): fix O(n^2) CSV read, smaller batch, progress bar#1836AllWorkNoPlay-95 wants to merge 5 commits into
AllWorkNoPlay-95 wants to merge 5 commits into
Conversation
getRows() called league/csv fetchOne($offset+$i) in a loop, and fetchOne re-scans the file from the start on every call, making imports O(n^2) (~12.5M line-parses for 5000 rows). Read each batch once via Statement::offset()->limit(). Add getTotalRows() so the UI can compute import progress.
Shorter per-request work (less risk of proxy/PHP timeouts on large files) and more frequent progress updates.
Replace the full-screen spinner with a progress overlay that updates after each batch (processed/total rows + percentage). Show the actual server error instead of '[object Object]' when an import request fails.
Anagrafiche imports geolocate each row via an online service when 'Geolocalizzazione automatica' is enabled, which slows the import. Show a dynamic notice in the progress overlay only when the setting is active for an anagrafiche import.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Descrizione
Migliora performance, robustezza e UX dell'importazione CSV (
modules/import), in particolare per file grandi (migliaia di righe).1. Lettura del batch in un'unica passata — fix O(n²)
CSVImporter::getRows()leggeva ogni riga con$this->csv->fetchOne($offset + $i)in un ciclo.league/csv::fetchOne()ri-scorre il file dall'inizio ad ogni chiamata, quindi l'importazione era quadratica (~12,5 milioni di parse di riga per 5000 righe, con rallentamento progressivo verso la fine). Ora il batch viene letto una sola volta conStatement::create()->offset()->limit().Risultato misurato: testato su un'importazione reale di 5000+ anagrafiche clienti, l'avanzamento che prima richiedeva diversi minuti ora si completa in pochi secondi.
2. Dimensione del batch 500 → 100
Richieste più brevi (meno rischio di timeout del proxy / PHP su file grandi) e aggiornamenti di avanzamento più frequenti.
3. Progress bar + messaggi di errore leggibili (
modules/import/edit.php)CSVImporter::getTotalRows().errordiajaxSubmitconcatenava l'oggettojqXHRin una stringa, mostrando[object Object]. Ora viene mostrato il messaggio reale (responseJSON.message→responseText→statusText).4. Avvisi all'utente nell'overlay di avanzamento
Nessuna nuova dipendenza richiesta. Nessuna modifica allo schema.
Risolve: ISSUE 1459
Tipologia
Checklist
Nota sul check Codacy (da ignorare)
Codacy segnala su alcune righe "All output should be run through an escaping function … found 'tr'" (es.
modules/import/edit.php, la riga contr('Importazione in corso...')).È un falso positivo: la regola proviene dai WordPress Coding Standards (
WordPress.Security.EscapeOutput), che pretendeesc_html()/esc_attr()e non riconoscetr()come funzione di escaping. OSM non è WordPress e usatr()come funzione standard di traduzione/output in tutto il progetto (centinaia di occorrenze). Le righe introdotte qui seguono esattamente la stessa convenzione già presente nello stesso file (es. le righe pre-esistenti contr('Informazioni importanti:'),tr('Campi obbligatori (*):'), ecc.). Inoltre gli argomenti ditr()sono stringhe statiche, non input utente.La segnalazione può quindi essere ignorata.