From 3766d28206d39499951ca0a9aba1ef73196cdfe9 Mon Sep 17 00:00:00 2001 From: Kelrap Date: Fri, 14 Jun 2024 10:04:51 -0400 Subject: [PATCH 1/4] Fetched choices don't affect cache --- lib/pangea/repo/span_data_repo.dart | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/pangea/repo/span_data_repo.dart b/lib/pangea/repo/span_data_repo.dart index e253bb1d0..a60f2c4e2 100644 --- a/lib/pangea/repo/span_data_repo.dart +++ b/lib/pangea/repo/span_data_repo.dart @@ -80,15 +80,27 @@ class SpanDetailsRepoReqAndRes { bool operator ==(Object other) { if (identical(this, other)) return true; if (other is! SpanDetailsRepoReqAndRes) return false; - - return toJson().toString() == other.toJson().toString(); + if (other.userL1 != userL1) return false; + if (other.userL2 != userL2) return false; + if (other.enableIT != enableIT) return false; + if (other.enableIGC != enableIGC) return false; + if (other.span.message != span.message) return false; + // if (other.span.context != span.context) return false; + return true; } /// Overrides the hashCode getter to generate a hash code for the [SpanDetailsRepoReqAndRes] object. /// Used as keys in response cache in igc_controller. @override int get hashCode { - return toJson().toString().hashCode; + return Object.hashAll([ + userL1.hashCode, + userL2.hashCode, + enableIT.hashCode, + enableIGC.hashCode, + span.message.hashCode, + // span.context.hashCode, + ]); } } From 83d7842e94c456c683267c88a0576c62ab50918d Mon Sep 17 00:00:00 2001 From: Kelrap Date: Fri, 14 Jun 2024 11:38:58 -0400 Subject: [PATCH 2/4] More specific cache calculation --- lib/pangea/repo/span_data_repo.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/pangea/repo/span_data_repo.dart b/lib/pangea/repo/span_data_repo.dart index a60f2c4e2..7a4b378e1 100644 --- a/lib/pangea/repo/span_data_repo.dart +++ b/lib/pangea/repo/span_data_repo.dart @@ -85,6 +85,11 @@ class SpanDetailsRepoReqAndRes { if (other.enableIT != enableIT) return false; if (other.enableIGC != enableIGC) return false; if (other.span.message != span.message) return false; + // if (other.span.shortMessage != span.shortMessage) return false; + if (other.span.offset != span.offset) return false; + if (other.span.length != span.length) return false; + if (other.span.fullText != span.fullText) return false; + // if (other.span.type != span.type) return false; // if (other.span.context != span.context) return false; return true; } @@ -99,6 +104,11 @@ class SpanDetailsRepoReqAndRes { enableIT.hashCode, enableIGC.hashCode, span.message.hashCode, + // span.shortMessage.hashCode, + span.offset.hashCode, + span.length.hashCode, + span.fullText.hashCode, + // span.type.hashCode, // span.context.hashCode, ]); } From 0983b11857271a09991775102d6ce98d93a83eeb Mon Sep 17 00:00:00 2001 From: Kelrap Date: Fri, 14 Jun 2024 12:39:32 -0400 Subject: [PATCH 3/4] Bot_style uses theme color for text --- lib/pangea/utils/bot_style.dart | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/pangea/utils/bot_style.dart b/lib/pangea/utils/bot_style.dart index 3791c205e..1a3a2f8fb 100644 --- a/lib/pangea/utils/bot_style.dart +++ b/lib/pangea/utils/bot_style.dart @@ -19,11 +19,7 @@ class BotStyle { AppConfig.fontSizeFactor * (big == true ? 1.2 : 1), fontStyle: italics ? FontStyle.italic : null, - color: setColor - ? Theme.of(context).brightness == Brightness.dark - ? AppConfig.primaryColorLight - : AppConfig.primaryColor - : null, + color: setColor ? Theme.of(context).colorScheme.primary : null, inherit: true, ); From 01dc89f199383b96f0ca2940a6faba855c428a6b Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 14 Jun 2024 13:07:26 -0400 Subject: [PATCH 4/4] clear cache on send and before getting language help, update span data hashcode --- .../controllers/igc_controller.dart | 4 +++ lib/pangea/repo/span_data_repo.dart | 31 ++++++++++--------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/lib/pangea/choreographer/controllers/igc_controller.dart b/lib/pangea/choreographer/controllers/igc_controller.dart index b0c8dd462..d5fd0de95 100644 --- a/lib/pangea/choreographer/controllers/igc_controller.dart +++ b/lib/pangea/choreographer/controllers/igc_controller.dart @@ -55,6 +55,9 @@ class IgcController { try { if (choreographer.currentText.isEmpty) return clear(); + // the error spans are going to be reloaded, so clear the cache + _clearCache(); + debugPrint('getIGCTextData called with ${choreographer.currentText}'); debugPrint('getIGCTextData called with tokensOnly = $tokensOnly'); @@ -287,6 +290,7 @@ class IgcController { clear() { igcTextData = null; + _clearCache(); // Not sure why this is here // MatrixState.pAnyState.closeOverlay(); } diff --git a/lib/pangea/repo/span_data_repo.dart b/lib/pangea/repo/span_data_repo.dart index 7a4b378e1..f06363fd1 100644 --- a/lib/pangea/repo/span_data_repo.dart +++ b/lib/pangea/repo/span_data_repo.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:collection/collection.dart'; import 'package:fluffychat/pangea/config/environment.dart'; import 'package:fluffychat/pangea/enum/span_choice_type.dart'; import 'package:fluffychat/pangea/enum/span_data_type.dart'; @@ -84,13 +85,16 @@ class SpanDetailsRepoReqAndRes { if (other.userL2 != userL2) return false; if (other.enableIT != enableIT) return false; if (other.enableIGC != enableIGC) return false; - if (other.span.message != span.message) return false; - // if (other.span.shortMessage != span.shortMessage) return false; - if (other.span.offset != span.offset) return false; - if (other.span.length != span.length) return false; - if (other.span.fullText != span.fullText) return false; - // if (other.span.type != span.type) return false; - // if (other.span.context != span.context) return false; + if (other.span.choices + ?.firstWhere( + (choice) => choice.type == SpanChoiceType.bestCorrection, + ) + .value != + span.choices + ?.firstWhere( + (choice) => choice.type == SpanChoiceType.bestCorrection, + ) + .value) return false; return true; } @@ -103,13 +107,12 @@ class SpanDetailsRepoReqAndRes { userL2.hashCode, enableIT.hashCode, enableIGC.hashCode, - span.message.hashCode, - // span.shortMessage.hashCode, - span.offset.hashCode, - span.length.hashCode, - span.fullText.hashCode, - // span.type.hashCode, - // span.context.hashCode, + span.choices + ?.firstWhereOrNull( + (choice) => choice.type == SpanChoiceType.bestCorrection, + ) + ?.value + .hashCode, ]); } }