chore: reduce calls to subscription endpoint and profile endpoint (#3377)

This commit is contained in:
ggurdin 2025-07-08 15:35:12 -04:00 committed by GitHub
parent 8a249cd83a
commit 9b13e27a0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 109 additions and 24 deletions

View file

@ -1,3 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:fluffychat/pangea/instructions/instructions_enum.dart';
import 'package:fluffychat/widgets/matrix.dart';
@ -54,4 +56,35 @@ class InstructionSettings {
InstructionSettings copy() {
return InstructionSettings(Map<String, bool>.from(_instructions));
}
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
if (other is! InstructionSettings) return false;
final entries = _instructions.entries.toList()
..sort((a, b) => a.key.hashCode.compareTo(b.key.hashCode));
final otherEntries = other._instructions.entries.toList()
..sort((a, b) => a.key.hashCode.compareTo(b.key.hashCode));
return listEquals(
entries.map((e) => e.key).toList(),
otherEntries.map((e) => e.key).toList(),
) &&
listEquals(
entries.map((e) => e.value).toList(),
otherEntries.map((e) => e.value).toList(),
);
}
@override
int get hashCode {
final entries = _instructions.entries.toList()
..sort((a, b) => a.key.hashCode.compareTo(b.key.hashCode));
return Object.hashAll(
entries.map((e) => Object.hash(e.key, e.value)),
);
}
}

View file

@ -96,19 +96,14 @@ class SubscriptionController extends BaseController {
availableSubscriptionInfo = AvailableSubscriptionsInfo();
await availableSubscriptionInfo!.setAvailableSubscriptions();
final subs =
await SubscriptionRepo.getCurrentSubscriptionInfo(null, null);
currentSubscriptionInfo = kIsWeb
? WebSubscriptionInfo(
userID: _userID!,
availableSubscriptionInfo: availableSubscriptionInfo!,
history: subs.allSubscriptions,
)
: MobileSubscriptionInfo(
userID: _userID!,
availableSubscriptionInfo: availableSubscriptionInfo!,
history: subs.allSubscriptions,
);
await currentSubscriptionInfo!.configure();
@ -162,13 +157,11 @@ class SubscriptionController extends BaseController {
userID: _userID!,
availableSubscriptionInfo:
availableSubscriptionInfo ?? AvailableSubscriptionsInfo(),
history: {},
)
: MobileSubscriptionInfo(
userID: _userID!,
availableSubscriptionInfo:
availableSubscriptionInfo ?? AvailableSubscriptionsInfo(),
history: {},
);
currentSubscriptionInfo!.currentSubscriptionId =

View file

@ -10,7 +10,6 @@ import 'package:fluffychat/widgets/matrix.dart';
class CurrentSubscriptionInfo {
final String userID;
final AvailableSubscriptionsInfo availableSubscriptionInfo;
final Map<String, RCSubscription>? history;
DateTime? expirationDate;
String? currentSubscriptionId;
@ -18,7 +17,6 @@ class CurrentSubscriptionInfo {
CurrentSubscriptionInfo({
required this.userID,
required this.availableSubscriptionInfo,
required this.history,
});
SubscriptionDetails? get currentSubscription {

View file

@ -15,7 +15,6 @@ class MobileSubscriptionInfo extends CurrentSubscriptionInfo {
MobileSubscriptionInfo({
required super.userID,
required super.availableSubscriptionInfo,
required super.history,
});
@override

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:fluffychat/config/app_config.dart';
@ -8,7 +10,6 @@ class WebSubscriptionInfo extends CurrentSubscriptionInfo {
WebSubscriptionInfo({
required super.userID,
required super.availableSubscriptionInfo,
required super.history,
});
@override
@ -16,7 +17,6 @@ class WebSubscriptionInfo extends CurrentSubscriptionInfo {
if (currentSubscriptionId != null) return;
try {
final rcResponse = await SubscriptionRepo.getCurrentSubscriptionInfo(
userID,
availableSubscriptionInfo.allProducts,
);

View file

@ -91,7 +91,6 @@ class SubscriptionRepo {
}
static Future<RCSubscriptionResponseModel> getCurrentSubscriptionInfo(
String? userId,
List<SubscriptionDetails>? allProducts,
) async {
final Requests req = Requests(

View file

@ -84,8 +84,14 @@ class UserController extends BaseController {
}) async {
final prevTargetLang = _pangeaController.languageController.userL2;
final prevBaseLang = _pangeaController.languageController.userL1;
final prevHash = profile.hashCode;
final Profile updatedProfile = update(profile);
if (updatedProfile.hashCode == prevHash) {
// no changes were made, so don't save
return;
}
await updatedProfile.saveProfileData(waitForDataInSync: waitForDataInSync);
Map<String, dynamic>? profileUpdate;

View file

@ -128,6 +128,34 @@ class UserSettings {
cefrLevel: cefrLevel,
);
}
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is UserSettings &&
other.dateOfBirth == dateOfBirth &&
other.createdAt == createdAt &&
other.autoPlayMessages == autoPlayMessages &&
other.publicProfile == publicProfile &&
other.targetLanguage == targetLanguage &&
other.sourceLanguage == sourceLanguage &&
other.country == country &&
other.hasJoinedHelpSpace == hasJoinedHelpSpace &&
other.cefrLevel == cefrLevel;
}
@override
int get hashCode =>
dateOfBirth.hashCode ^
createdAt.hashCode ^
autoPlayMessages.hashCode ^
publicProfile.hashCode ^
targetLanguage.hashCode ^
sourceLanguage.hashCode ^
country.hashCode ^
hasJoinedHelpSpace.hashCode ^
cefrLevel.hashCode;
}
/// The user's language tool settings.
@ -210,6 +238,30 @@ class UserToolSettings {
enableAutocorrect: enableAutocorrect,
);
}
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is UserToolSettings &&
other.interactiveTranslator == interactiveTranslator &&
other.interactiveGrammar == interactiveGrammar &&
other.immersionMode == immersionMode &&
other.definitions == definitions &&
other.autoIGC == autoIGC &&
other.enableTTS == enableTTS &&
other.enableAutocorrect == enableAutocorrect;
}
@override
int get hashCode =>
interactiveTranslator.hashCode ^
interactiveGrammar.hashCode ^
immersionMode.hashCode ^
definitions.hashCode ^
autoIGC.hashCode ^
enableTTS.hashCode ^
enableAutocorrect.hashCode;
}
/// A wrapper around the matrix account data for the user profile.
@ -329,6 +381,22 @@ class Profile {
instructionSettings: instructionSettings.copy(),
);
}
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is Profile &&
other.userSettings == userSettings &&
other.toolSettings == toolSettings &&
other.instructionSettings == instructionSettings;
}
@override
int get hashCode =>
userSettings.hashCode ^
toolSettings.hashCode ^
instructionSettings.hashCode;
}
/// Model of data from pangea chat server. Not used anymore, in favor of matrix account data.

View file

@ -178,17 +178,6 @@ flutter:
- assets/sounds/
- assets/vodozemac/
# #Pangea
fonts:
- family: Inconsolata
fonts:
- asset: fonts/Inconsolata/Inconsolata-Regular.ttf
- asset: fonts/Inconsolata/Inconsolata-Light.ttf
style: italic
- asset: fonts/Inconsolata/Inconsolata-Bold.ttf
weight: 700
# Pangea#
msix_config:
display_name: FluffyChat
publisher_display_name: FluffyChat