feat: Introduce PDFService for optimized PDF generation and caching in container and equipment management
This commit is contained in:
@@ -111,13 +111,16 @@ class QRCodeService {
|
||||
return _cachedLogoImage!;
|
||||
}
|
||||
|
||||
/// Génère plusieurs QR codes en parallèle (optimisé)
|
||||
/// Génère plusieurs QR codes en parallèle par batches optimisés (réduit les lags)
|
||||
static Future<List<Uint8List>> generateBulkQRCodes(
|
||||
List<String> dataList, {
|
||||
double size = 512,
|
||||
bool withLogo = false,
|
||||
bool useCache = true,
|
||||
Function(int, int)? onProgress, // Callback de progression
|
||||
}) async {
|
||||
if (dataList.isEmpty) return [];
|
||||
|
||||
// Si tout est en cache, retourner immédiatement
|
||||
if (useCache) {
|
||||
final allCached = dataList.every((data) {
|
||||
@@ -133,28 +136,46 @@ class QRCodeService {
|
||||
}
|
||||
}
|
||||
|
||||
// Batching adaptatif optimisé selon la taille et le nombre
|
||||
// Batching adaptatif ultra-optimisé
|
||||
int batchSize;
|
||||
if (size <= 200) {
|
||||
batchSize = 100; // Petits QR : lots de 100
|
||||
if (dataList.length <= 10) {
|
||||
// Pour petites quantités, tout en une fois
|
||||
batchSize = dataList.length;
|
||||
} else if (size <= 200) {
|
||||
batchSize = 20; // Petits QR : lots de 20 (réduit de 100)
|
||||
} else if (size <= 300) {
|
||||
batchSize = 50; // Moyens QR : lots de 50
|
||||
} else if (size <= 500) {
|
||||
batchSize = 20; // Grands QR : lots de 20
|
||||
batchSize = 10; // Moyens QR : lots de 10 (réduit de 50)
|
||||
} else if (size <= 400) {
|
||||
batchSize = 5; // Grands QR : lots de 5 (réduit de 20)
|
||||
} else {
|
||||
batchSize = 10; // Très grands : lots de 10
|
||||
batchSize = 3; // Très grands : lots de 3 (réduit de 10)
|
||||
}
|
||||
|
||||
final List<Uint8List> results = [];
|
||||
int processed = 0;
|
||||
|
||||
for (int i = 0; i < dataList.length; i += batchSize) {
|
||||
final batch = dataList.skip(i).take(batchSize).toList();
|
||||
|
||||
// Générer le batch
|
||||
final batchResults = await Future.wait(
|
||||
batch.map((data) => withLogo
|
||||
? generateQRCodeWithLogo(data, size: size, useCache: useCache)
|
||||
: generateQRCode(data, size: size, useCache: useCache)),
|
||||
);
|
||||
|
||||
results.addAll(batchResults);
|
||||
processed += batch.length;
|
||||
|
||||
// Callback de progression
|
||||
if (onProgress != null) {
|
||||
onProgress(processed, dataList.length);
|
||||
}
|
||||
|
||||
// Pause micro pour éviter de bloquer l'UI (seulement pour gros batches)
|
||||
if (batchSize >= 5 && i + batchSize < dataList.length) {
|
||||
await Future.delayed(const Duration(milliseconds: 10));
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
|
||||
Reference in New Issue
Block a user