cache pangea reps so direct translation is not called multiple times, don't translate names of audio message files
This commit is contained in:
parent
1d507226f3
commit
614f83ad29
2 changed files with 44 additions and 2 deletions
|
|
@ -18,8 +18,7 @@ class MessageDataController extends BaseController {
|
|||
late PangeaController _pangeaController;
|
||||
|
||||
final List<CacheItem> _cache = [];
|
||||
|
||||
final Map<String, MessageDataQueueItem> _messageDataToSave = {};
|
||||
final List<RepresentationCacheItem> _representationCache = [];
|
||||
|
||||
MessageDataController(PangeaController pangeaController) {
|
||||
_pangeaController = pangeaController;
|
||||
|
|
@ -31,6 +30,14 @@ class MessageDataController extends BaseController {
|
|||
e.parentId == parentId && e.type == type && e.langCode == langCode,
|
||||
);
|
||||
|
||||
RepresentationCacheItem? getRepresentationCacheItem(
|
||||
String parentId,
|
||||
String langCode,
|
||||
) =>
|
||||
_representationCache.firstWhereOrNull(
|
||||
(e) => e.parentId == parentId && e.langCode == langCode,
|
||||
);
|
||||
|
||||
Future<PangeaMessageTokens?> _getTokens(
|
||||
TokensRequestModel req,
|
||||
) async {
|
||||
|
|
@ -141,6 +148,32 @@ class MessageDataController extends BaseController {
|
|||
required String? source,
|
||||
required String target,
|
||||
required Room room,
|
||||
}) async {
|
||||
final RepresentationCacheItem? item =
|
||||
getRepresentationCacheItem(text, target);
|
||||
if (item != null) return item.data;
|
||||
|
||||
_representationCache.add(
|
||||
RepresentationCacheItem(
|
||||
text,
|
||||
target,
|
||||
_getPangeaRepresentation(
|
||||
text: text,
|
||||
source: source,
|
||||
target: target,
|
||||
room: room,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return _representationCache.last.data;
|
||||
}
|
||||
|
||||
Future<PangeaRepresentation?> _getPangeaRepresentation({
|
||||
required String text,
|
||||
required String? source,
|
||||
required String target,
|
||||
required Room room,
|
||||
}) async {
|
||||
final req = FullTextTranslationRequestModel(
|
||||
text: text,
|
||||
|
|
@ -235,3 +268,11 @@ class CacheItem {
|
|||
|
||||
CacheItem(this.parentId, this.type, this.langCode, this.data);
|
||||
}
|
||||
|
||||
class RepresentationCacheItem {
|
||||
String parentId;
|
||||
String langCode;
|
||||
Future<PangeaRepresentation?> data;
|
||||
|
||||
RepresentationCacheItem(this.parentId, this.langCode, this.data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ class GetChatListItemSubtitle {
|
|||
}
|
||||
|
||||
if (event.type != EventTypes.Message ||
|
||||
event.messageType != MessageTypes.Text ||
|
||||
!pangeaController.permissionsController
|
||||
.isToolEnabled(ToolSetting.immersionMode, event.room)) {
|
||||
return event.calcLocalizedBody(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue