Skip to content

Commit acb356e

Browse files
committed
refactor(api): remove unused currentPreferences from limit service
This refactoring removes the unused currentPreferences parameter from the UserPreferenceLimitService and its implementation. The checkUserContentPreferencesLimits method signature has been updated in both the interface and the concrete implementation. The custom updater in data_operation_registry.dart no longer performs an unnecessary database read to fetch the current preferences, improving efficiency. This change simplifies the code and aligns it with the stateless validation logic, where only the final proposed state (updatedPreferences) is needed for limit checks.
1 parent 0e49173 commit acb356e

File tree

3 files changed

+3
-13
lines changed

3 files changed

+3
-13
lines changed

lib/src/registry/data_operation_registry.dart

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import 'package:core/core.dart';
44
import 'package:dart_frog/dart_frog.dart';
55
import 'package:data_repository/data_repository.dart';
66
import 'package:flutter_news_app_api_server_full_source_code/src/middlewares/ownership_check_middleware.dart';
7-
import 'package:flutter_news_app_api_server_full_source_code/src/rbac/permissions.dart';
87
import 'package:flutter_news_app_api_server_full_source_code/src/rbac/permission_service.dart';
8+
import 'package:flutter_news_app_api_server_full_source_code/src/rbac/permissions.dart';
99
import 'package:flutter_news_app_api_server_full_source_code/src/services/country_query_service.dart';
1010
import 'package:flutter_news_app_api_server_full_source_code/src/services/dashboard_summary_service.dart';
1111
import 'package:flutter_news_app_api_server_full_source_code/src/services/push_notification_service.dart';
@@ -395,16 +395,9 @@ class DataOperationRegistry {
395395

396396
final preferencesToUpdate = item as UserContentPreferences;
397397

398-
// 1. Fetch the current state of the user's preferences.
399-
final currentPreferences = await userContentPreferencesRepository.read(
400-
id: id,
401-
);
402-
403398
// 2. Validate all limits using the consolidated service method.
404-
// The service now contains all logic to compare the updated and
405-
// current preferences and check all relevant limits.
406-
//
407-
// We first check if the user has permission to bypass these limits.
399+
// The service validates the entire proposed state. We first check
400+
// if the user has permission to bypass these limits.
408401
if (permissionService.hasPermission(
409402
authenticatedUser,
410403
Permissions.userPreferenceBypassLimits,
@@ -416,7 +409,6 @@ class DataOperationRegistry {
416409
await userPreferenceLimitService.checkUserContentPreferencesLimits(
417410
user: authenticatedUser,
418411
updatedPreferences: preferencesToUpdate,
419-
currentPreferences: currentPreferences,
420412
);
421413
}
422414

lib/src/services/default_user_preference_limit_service.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class DefaultUserPreferenceLimitService implements UserPreferenceLimitService {
2626
Future<void> checkUserContentPreferencesLimits({
2727
required User user,
2828
required UserContentPreferences updatedPreferences,
29-
required UserContentPreferences currentPreferences,
3029
}) async {
3130
_log.info(
3231
'Checking all user content preferences limits for user ${user.id}.',

lib/src/services/user_preference_limit_service.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ abstract class UserPreferenceLimitService {
1919
Future<void> checkUserContentPreferencesLimits({
2020
required User user,
2121
required UserContentPreferences updatedPreferences,
22-
required UserContentPreferences currentPreferences,
2322
});
2423
}

0 commit comments

Comments
 (0)