Skip to content

Commit 6efd2ce

Browse files
committed
💫improve performance.
Restrict unnecessary api calls
1 parent 4cbc6c5 commit 6efd2ce

22 files changed

+101
-82
lines changed

‎lib/bloc/bloc/repo_event.dart‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ class LoadForksEvent extends RepoEvent {
5858
final bool isLoadNextForks;
5959
final String name;
6060
final String owner;
61-
LoadForksEvent({this.isLoadNextForks=false,this.name,this.owner}) : assert(name != null), assert(owner!= null);
61+
final int count;
62+
LoadForksEvent({this.name,this.owner,this.count,this.isLoadNextForks=false}) : assert(name != null), assert(owner!= null);
6263
@override
6364
Stream<RepoState> getRepoForks(
6465
{RepoState currentState, RepoBloc bloc}) async* {
6566
try {
6667
yield LoadingForksState();
67-
68-
final list = await _repoRepository.fetchRepoForks(name: name, owner: owner);
68+
final list = count == 0 ? null : await _repoRepository.fetchRepoForks(name: name, owner: owner);
6969
yield LoadedForksState(list);
7070
} catch (_, stackTrace) {
7171
developer.log('$_',name: 'LoadForksEvent', error: _, stackTrace: stackTrace);

‎lib/bloc/gist/gist_event.dart‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ class LoadGistDetailEvent extends GistEvent {
3131
}
3232

3333
class OnGistLoad extends GistEvent {
34-
OnGistLoad(this.login, {this.isLoadNextGist = false});
34+
OnGistLoad(this.login, {this.count,this.isLoadNextGist = false});
3535

3636
final bool isLoadNextGist;
3737
final String login;
38-
38+
final int count;
3939
@override
4040
Stream<GistState> getGist(
4141
{GistState currentState, GistBloc bloc}) async* {
@@ -45,7 +45,7 @@ class OnGistLoad extends GistEvent {
4545
try {
4646
// yield LoadingUserState();
4747

48-
final gistModel = await _gistRepository.fetchGistList(login: login);
48+
final gistModel = count == 0 ? null : await _gistRepository.fetchGistList(login: login);
4949

5050
yield LoadedGitState(gist: gistModel);
5151
} catch (_, stackTrace) {

‎lib/bloc/gist/gist_state.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class LoadedGitState extends GistState {
3838
print("New cursor is ${gistModel.pageInfo.endCursor}");
3939
return LoadedGitState(gist: currenctGistModel,);
4040
}
41+
42+
bool get isNotNullEmpty => this.gist != null && this.gist.totalCount > 0;
4143
}
4244

4345
class LoadingNextGistState extends LoadedGitState {

‎lib/bloc/issues/issues_event.dart‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ abstract class IssuesEvent extends Equatable {
2222

2323
class LoadIssuesEvent extends IssuesEvent {
2424
final String login;
25+
final int count;
2526
final bool isLoadNextIssues;
2627

27-
LoadIssuesEvent(this.login, {this.isLoadNextIssues = false});
28+
LoadIssuesEvent(this.login, {this.count,this.isLoadNextIssues = false});
2829
@override
2930
Stream<IssuesState> loadIssues(
3031
{IssuesState currentState, IssuesBloc bloc}) async* {
@@ -33,7 +34,7 @@ class LoadIssuesEvent extends IssuesEvent {
3334
return;
3435
}
3536
yield LoadingUserIssuesState();
36-
final issues = await _issuesRepository.getIssues(login: login);
37+
final issues =count ==0 ? null : await _issuesRepository.getIssues(login: login);
3738
yield LoadedIssuesState(issues);
3839
} catch (_, stackTrace) {
3940
developer.log('$_',
@@ -70,9 +71,10 @@ class LoadIssuesEvent extends IssuesEvent {
7071
class LoadRepoIssuesEvent extends IssuesEvent {
7172
final String owner;
7273
final String name;
74+
final int count;
7375
final bool isLoadNextRepoIssues;
7476

75-
LoadRepoIssuesEvent({this.owner,this.name, this.isLoadNextRepoIssues = false});
77+
LoadRepoIssuesEvent({this.owner,this.name,this.count,this.isLoadNextRepoIssues = false});
7678
@override
7779
Stream<IssuesState> loadRepoIssues(
7880
{IssuesState currentState, IssuesBloc bloc}) async* {
@@ -81,7 +83,7 @@ class LoadRepoIssuesEvent extends IssuesEvent {
8183
return;
8284
}
8385
yield LoadingRepoIssuesState();
84-
final issues = await _issuesRepository.getRepoIssues(name:name,owner:owner);
86+
final issues = count == 0 ? null : await _issuesRepository.getRepoIssues(name:name,owner:owner);
8587
yield LoadedRepoIssuesState(issues);
8688
} catch (_, stackTrace) {
8789
developer.log('$_',

‎lib/bloc/issues/issues_state.dart‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class LoadedRepoIssuesState extends IssuesState {
5959
currentIssueModel.pageInfo = issuesModel.pageInfo;
6060
return LoadedRepoIssuesState(currentIssueModel);
6161
}
62+
63+
bool get isNotNullEmpty => this.issues != null && this.issues.list != null &&
64+
this.issues.list.isNotEmpty;
6265
}
6366

6467
class ErrorRepoIssuesState extends IssuesState {

‎lib/bloc/notification/notification_event.dart‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ class OnLoad extends NotificationEvent {
3131
}
3232
yield LoadingNotificationState();
3333
final list = await _userRepository.getNotificationsList(pageNo: 1);
34-
yield LoadedNotificationState(
35-
list: list, pageNo: 2, hasNextPage: list.length == 10);
34+
yield LoadedNotificationState(list: null, pageNo: 2, hasNextPage: list.length == 10);
3635
} catch (_, stackTrace) {
3736
developer.log('$_',
3837
name: 'Load Repository Event', error: _, stackTrace: stackTrace);
@@ -48,8 +47,7 @@ class OnLoad extends NotificationEvent {
4847
print("No notification left");
4948
return;
5049
}
51-
yield LoadingNextNotificationState(
52-
state.list, state.pageNo, state.hasNextPage);
50+
yield LoadingNextNotificationState(state.list, state.pageNo, state.hasNextPage);
5351
final list = await _userRepository.getNotificationsList(pageNo: state.pageNo);
5452
yield LoadedNotificationState.next(
5553
currentList: state.list,

‎lib/bloc/people/people_event.dart‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,20 @@ class LoadUserEvent extends PeopleEvent {
8484
}
8585

8686
class LoadFollowEvent extends PeopleEvent {
87-
LoadFollowEvent(this.login, this.type, {this.isLoadNextFollow = false});
87+
LoadFollowEvent(this.login, this.type, {this.count, this.isLoadNextFollow = false});
8888

8989
final bool isLoadNextFollow;
9090
final String login;
9191
final PeopleType type;
92+
final int count;
9293

9394
@override
9495
Stream<PeopleState> fetchFollowersList(
9596
{PeopleState currentState, PeopleBloc bloc}) async* {
9697
try {
9798
if (!isLoadNextFollow) {
9899
yield LoadingFollowState();
99-
final followers =
100-
await _peopleRepository.fetchFollowersList(login, type: type);
100+
final followers = count == 0 ? null : await _peopleRepository.fetchFollowersList(login, type: type);
101101
yield LoadedFollowState(followers);
102102
} else {
103103
final state = currentState as LoadedFollowState;
@@ -108,8 +108,7 @@ class LoadFollowEvent extends PeopleEvent {
108108
yield LoadingNextFollowState(state.followModel);
109109
final followModel = await _peopleRepository.fetchFollowersList(login,
110110
type: type, endCursor: state.followModel.pageInfo.endCursor);
111-
yield LoadedFollowState.next(
112-
model: followModel, currentFollowModel: state.followModel);
111+
yield LoadedFollowState.next(model: followModel, currentFollowModel: state.followModel);
113112
}
114113
} on OperationException catch (_, stackTrace) {
115114
developer.log('$_',
@@ -174,14 +173,15 @@ class LoadWatchersEvent extends PeopleEvent {
174173
final bool isLoadNextWatchers;
175174
final String name;
176175
final String owner;
177-
LoadWatchersEvent({this.isLoadNextWatchers=false,this.name,this.owner}) : assert(name != null), assert(owner!= null);
176+
final int count;
177+
LoadWatchersEvent({this.isLoadNextWatchers=false,this.count,this.name,this.owner}) : assert(name != null), assert(owner!= null);
178178
@override
179179
Stream<PeopleState> getRepoWatchers(
180180
{PeopleState currentState, PeopleBloc bloc}) async* {
181181
try {
182182
yield LoadingWatcherState();
183183

184-
final list = await _peopleRepository.getRepoWatchers(name: name, owner: owner);
184+
final list = count == 0 ? null : await _peopleRepository.getRepoWatchers(name: name, owner: owner);
185185
yield LoadedWatcherState(list);
186186
} catch (_, stackTrace) {
187187
developer.log('$_',
@@ -213,14 +213,14 @@ class LoadStargezersEvent extends PeopleEvent {
213213
final bool isLoadNextStartgers;
214214
final String name;
215215
final String owner;
216-
LoadStargezersEvent({this.isLoadNextStartgers=false,this.name,this.owner}) : assert(name != null), assert(owner!= null);
216+
final int count;
217+
LoadStargezersEvent({this.name,this.owner, this.count,this.isLoadNextStartgers=false}) : assert(name != null), assert(owner!= null);
217218
@override
218219
Stream<PeopleState> getRepoStargezres(
219220
{PeopleState currentState, PeopleBloc bloc}) async* {
220221
try {
221222
yield LoadingStargezersState();
222-
223-
final list = await _peopleRepository.fetchRepoStargazers(name: name, owner: owner);
223+
final list = count == 0 ? null : await _peopleRepository.fetchRepoStargazers(name: name, owner: owner);
224224
yield LoadedStargezersState(list);
225225
} catch (_, stackTrace) {
226226
developer.log('$_',name: 'LoadStargezersEvent', error: _, stackTrace: stackTrace);

‎lib/bloc/people/people_state.dart‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ class LoadedStargezersState extends PeopleState {
155155
currentStargazers.pageInfo = stargezers.pageInfo;
156156
return LoadedStargezersState(currentStargazers);
157157
}
158+
159+
bool get isNotNullEmpty => this.stargezers != null && this.stargezers.userList != null &&
160+
this.stargezers.userList.isNotEmpty;
158161
}
159162
class ErrorStargezersState extends LoadedUserState {
160163
final String errorMessage;

‎lib/bloc/pullrequest/pullrequest_event.dart‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@ abstract class PullrequestEvent extends Equatable{
1212
class LoadRepoPullRequests extends PullrequestEvent {
1313
final String owner;
1414
final String name;
15+
final int count;
1516
final bool isNextRepoPull;
1617

1718

18-
LoadRepoPullRequests({this.name, this.owner,this.isNextRepoPull = false}) : assert(owner != null),assert(name!= null);
19+
LoadRepoPullRequests({this.name, this.owner,this.count,this.isNextRepoPull = false}) : assert(owner != null),assert(name!= null);
1920

2021
@override
2122
Stream<PullrequestState> getrepoPullrequest(
2223
{PullrequestState currentState, PullrequestBloc bloc}) async* {
2324
try {
2425
yield LoadingRepoPullRequest();
2526

26-
final repoPullRequest = await _pullrequestRepository.fetchRepoPullRequest(name:name, owner:owner);
27+
final repoPullRequest = count == 0 ? null : await _pullrequestRepository.fetchRepoPullRequest(name:name, owner:owner);
2728
yield LoadedRepoPullRequest(repoPullRequest: repoPullRequest);
2829
} catch (_, stackTrace) {
2930
developer.log('$_', name: 'LoadPullrequestEvent', error: _, stackTrace: stackTrace);
@@ -57,11 +58,11 @@ class LoadRepoPullRequests extends PullrequestEvent {
5758
}
5859

5960
class OnPullRequestLoad extends PullrequestEvent {
60-
OnPullRequestLoad(this.login, {this.isLoadNextIssues = false});
61+
OnPullRequestLoad(this.login, {this.count,this.isLoadNextIssues = false});
6162

6263
final bool isLoadNextIssues;
6364
final String login;
64-
65+
final int count;
6566
@override
6667
Stream<PullrequestState> getPullRequest(
6768
{PullrequestState currentState, PullrequestBloc bloc}) async* {
@@ -70,8 +71,7 @@ class OnPullRequestLoad extends PullrequestEvent {
7071
}
7172
try {
7273
yield LoadingPullRequestState();
73-
final pullRequestsList =
74-
await _pullrequestRepository.fetchUserPullRequest(login:login);
74+
final pullRequestsList = count == 0 ? null : await _pullrequestRepository.fetchUserPullRequest(login:login);
7575
yield LoadedPullRequestState(pullRequestsList: pullRequestsList);
7676
} catch (_, stackTrace) {
7777
developer.log('$_',

‎lib/ui/page/home/widgets/home_page_screen.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class HomePageScreenBody extends StatelessWidget {
126126
children: <Widget>[
127127
_getUtilRos(context, GIcons.issue_opened_24, "Issues",
128128
color: GColors.green, onPressed: () {
129-
Navigator.push(context, IssuesPage.route(model.login));
129+
Navigator.push(context, IssuesPage.route(model.login,count:model.issues.totalCount));
130130
}),
131131
Divider(height: 0, indent: 50),
132132
_getUtilRos(context, GIcons.git_pull_request_16, "Pull Request",

0 commit comments

Comments
 (0)