Compare commits

..

2 commits

Author SHA1 Message Date
7b358a84ef Auto-sync: 20260304_224032 2026-03-04 22:40:33 +01:00
11c77a462f Auto-sync: 20260304_220000 2026-03-04 22:00:01 +01:00
2 changed files with 31 additions and 1 deletions

BIN
.DS_Store vendored

Binary file not shown.

View file

@ -33,6 +33,12 @@ class _ScambioDatiScreenState extends State<ScambioDatiScreen> with SingleTicker
void initState() {
super.initState();
// 🧹 AVVIO DEL NETTURBINO (con 10% di probabilità per non intasare il server)
if (Random().nextInt(10) == 0) {
_pulisciVecchieSessioni();
}
// RIMOZIONE DELLA SECONDA CHIAMATA LIBERA
// LOGICA DI APERTURA INTELLIGENTE:
// Lato A -> Inizia con la Fotocamera (Indice 1)
// Lato B -> Inizia mostrando il QR (Indice 0)
@ -44,6 +50,29 @@ class _ScambioDatiScreenState extends State<ScambioDatiScreen> with SingleTicker
_avviaHost();
}
// --- 🧹 IL NETTURBINO (GARBAGE COLLECTOR) ---
// Cerca nel database le sessioni più vecchie di 2 ore e le distrugge
Future<void> _pulisciVecchieSessioni() async {
try {
final dueOreFa = DateTime.now().subtract(const Duration(hours: 2));
final snapshot = await FirebaseFirestore.instance
.collection('scambi_cid')
.where('timestamp_scambio', isLessThan: Timestamp.fromDate(dueOreFa))
.get();
int cancellati = 0;
for (var doc in snapshot.docs) {
await doc.reference.delete();
cancellati++;
}
debugPrint("🧹 [NETTURBINO] Pulizia completata: eliminate $cancellati sessioni vecchie.");
} catch (e) {
debugPrint("⚠️ [NETTURBINO] Errore durante la pulizia: $e");
}
}
@override
void dispose() {
// Cancello la sessione se esco senza concludere, a meno che non sia l'ID della firma
@ -442,3 +471,4 @@ class _ScambioDatiScreenState extends State<ScambioDatiScreen> with SingleTicker
);
}
}
// Test di sincronizzazione forzata ore 22:40