From 2c82dfc7d7f31b680c9c1caa4430995ad88f7f3d Mon Sep 17 00:00:00 2001 From: ggurdin Date: Wed, 19 Jun 2024 15:12:08 -0400 Subject: [PATCH] added completer to updateAnalytics function to prevent it running many times in a row, also save empty analytics data once to indicate that chats have been checked and none was found --- .../controllers/my_analytics_controller.dart | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/pangea/controllers/my_analytics_controller.dart b/lib/pangea/controllers/my_analytics_controller.dart index cd95dd002..77a644863 100644 --- a/lib/pangea/controllers/my_analytics_controller.dart +++ b/lib/pangea/controllers/my_analytics_controller.dart @@ -148,7 +148,28 @@ class MyAnalyticsController extends BaseController { } } + Completer? _updateCompleter; Future updateAnalytics() async { + if (!(_updateCompleter?.isCompleted ?? true)) { + await _updateCompleter!.future; + return; + } + _updateCompleter = Completer(); + try { + await _updateAnalytics(); + } catch (err, s) { + ErrorHandler.logError( + e: err, + m: "Failed to update analytics", + s: s, + ); + } finally { + _updateCompleter?.complete(); + _updateCompleter = null; + } + } + + Future _updateAnalytics() async { // top level analytics sending function. Send analytics // for each type of analytics event // to each of the applicable analytics rooms @@ -237,7 +258,11 @@ class MyAnalyticsController extends BaseController { } // send the analytics data to the analytics room - if (analyticsContent.isEmpty) return; + // if there is no data to send, don't send an event, + // unless no events have been sent yet. In that case, send an event + // with no data to indicate that the the system checked for data + // and found none, so the system doesn't repeatedly check for data + if (analyticsContent.isEmpty && lastUpdated != null) return; await AnalyticsEvent.sendEvent( analyticsRoom, type,