Skip to content

Commit 69f73d3

Browse files
committed
perf(content_management): prevent redundant API calls for topics
- Add a condition to check if topics are already loaded and it's not a pagination request - If the condition is met, the function returns early without making a new API call - This optimization reduces unnecessary network requests when switching tabs
1 parent aa92f02 commit 69f73d3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/content_management/bloc/content_management_bloc.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ class ContentManagementBloc
174174
LoadTopicsRequested event,
175175
Emitter<ContentManagementState> emit,
176176
) async {
177+
// If topics are already loaded and it's not a pagination request,
178+
// do not re-fetch. This prevents redundant API calls on tab changes.
179+
if (state.topicsStatus == ContentManagementStatus.success &&
180+
state.topics.isNotEmpty &&
181+
event.startAfterId == null) {
182+
return;
183+
}
184+
177185
emit(state.copyWith(topicsStatus: ContentManagementStatus.loading));
178186
try {
179187
final isPaginating = event.startAfterId != null;

0 commit comments

Comments
 (0)