Compare commits
2 commits
87b07b2df5
...
7b358a84ef
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b358a84ef | |||
| 11c77a462f |
2 changed files with 31 additions and 1 deletions
BIN
.DS_Store
vendored
BIN
.DS_Store
vendored
Binary file not shown.
|
|
@ -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
|
||||
Loading…
Reference in a new issue