From cffc697df1b9d69840c2f59020a6ca31cee341bc Mon Sep 17 00:00:00 2001 From: wcjord <32568597+wcjord@users.noreply.github.com> Date: Wed, 22 Jan 2025 11:20:42 -0500 Subject: [PATCH] Move-cache-logic (#1501) * fix(igc-cache): fix logic not to ignore ignores :P * fix(cache logic): fix incorrect return --------- Co-authored-by: ggurdin <46800240+ggurdin@users.noreply.github.com> --- .../controllers/igc_controller.dart | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/pangea/choreographer/controllers/igc_controller.dart b/lib/pangea/choreographer/controllers/igc_controller.dart index b7adb7893..ba45a45dd 100644 --- a/lib/pangea/choreographer/controllers/igc_controller.dart +++ b/lib/pangea/choreographer/controllers/igc_controller.dart @@ -1,11 +1,6 @@ import 'dart:async'; import 'dart:developer'; -import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; - -import 'package:matrix/matrix.dart'; - import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart'; import 'package:fluffychat/pangea/choreographer/controllers/error_service.dart'; import 'package:fluffychat/pangea/choreographer/controllers/span_data_controller.dart'; @@ -14,6 +9,10 @@ import 'package:fluffychat/pangea/choreographer/models/pangea_match_model.dart'; import 'package:fluffychat/pangea/choreographer/repo/igc_repo.dart'; import 'package:fluffychat/pangea/choreographer/widgets/igc/span_card.dart'; import 'package:fluffychat/pangea/events/event_wrappers/pangea_message_event.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:matrix/matrix.dart'; + import '../../common/utils/error_handler.dart'; import '../../common/utils/overlay.dart'; import '../models/span_card_model.dart'; @@ -103,18 +102,16 @@ class IgcController { _initializeCacheClearing(); } - // Check if cached data exists - if (_igcTextDataCache.containsKey(reqBody.hashCode)) { - igcTextData = await _igcTextDataCache[reqBody.hashCode]!.data; - return; + // if the request is not in the cache, add it + if (!_igcTextDataCache.containsKey(reqBody.hashCode)) { + _igcTextDataCache[reqBody.hashCode] = _IGCTextDataCacheItem( + data: IgcRepo.getIGC( + choreographer.accessToken, + igcRequest: reqBody, + ), + ); } - final igcFuture = IgcRepo.getIGC( - choreographer.accessToken, - igcRequest: reqBody, - ); - _igcTextDataCache[reqBody.hashCode] = - _IGCTextDataCacheItem(data: igcFuture); final IGCTextData igcTextDataResponse = await _igcTextDataCache[reqBody.hashCode]!.data;