Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.

Commit f991fe7

Browse files
committed
Don't double fetch, add force fetch option
1 parent 65a4955 commit f991fe7

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

src/main/java/com/scorpiac/javarant/Rant.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,30 @@ private static String getImage(JsonElement image) {
7272
* @return The comments.
7373
*/
7474
public Comment[] getComments() {
75-
if (comments == null)
76-
fetchComments();
75+
fetchComments();
7776
return comments;
7877
}
7978

8079
/**
81-
* Fetch and store the comments on this rant.
80+
* Fetch and store the comments on this rant. If the comments are already fetched, they will not be fetched again.
8281
*
8382
* @return Whether the data was fetched successfully.
8483
*/
8584
public boolean fetchComments() {
85+
return fetchComments(false);
86+
}
87+
88+
/**
89+
* Fetch and store the comments on this rant.
90+
*
91+
* @param force Whether to fetch the data even if it was already fetched.
92+
* @return Whether the data was fetched successfully.
93+
*/
94+
public boolean fetchComments(boolean force) {
95+
// Check if we already fetched and force is false.
96+
if (comments != null && !force)
97+
return true;
98+
8699
// Rants url, rant id, app id.
87100
String url = String.format("%1$s/%2$d?app=%3$s", DevRant.API_RANTS_URL, this.getId(), DevRant.APP_ID);
88101
JsonObject json = DevRant.request(url);

src/main/java/com/scorpiac/javarant/User.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,23 @@ static User fromJson(JsonObject json) {
9090
}
9191

9292
/**
93-
* Fetch the user data from the user profile.
93+
* Fetch the user data from the user profile. If the data is already fetched, it will not be fetched again.
9494
*
9595
* @return Whether the data was fetched successfully.
9696
*/
9797
public boolean fetchData() {
98-
if (isFetched())
98+
return fetchData(false);
99+
}
100+
101+
/**
102+
* Fetch the user data from the user profile.
103+
*
104+
* @param force Whether to fetch the data even if it was already fetched.
105+
* @return Whether the data was fetched successfully.
106+
*/
107+
public boolean fetchData(boolean force) {
108+
// Check if we already fetched and force is false.
109+
if (fetched && !force)
99110
return true;
100111

101112
// Users url, user id, app id.

0 commit comments

Comments
 (0)