Auto-sync: 20260304_220000
This commit is contained in:
parent
87b07b2df5
commit
11c77a462f
1 changed files with 29 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue