Skip to content

Commit 8fb29ef

Browse files
[SDK-2485] Remove cached events (#1226)
* removing some disk operations * keep disk based tests * Update ServerRequest.java * Update ServerRequest.java * remove isPersistable
1 parent b0a209d commit 8fb29ef

File tree

3 files changed

+9
-70
lines changed

3 files changed

+9
-70
lines changed

Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,7 @@ private String getRequestUuid(String creationTsDateFormatted) {
169169
public boolean shouldRetryOnFail() {
170170
return false;
171171
}
172-
173-
/**
174-
* Specifies whether this request should be persisted to memory in order to re send in the next session
175-
*
176-
* @return {@code true} by default. Should be override for request that need not to be persisted
177-
*/
178-
boolean isPersistable() {
179-
return true;
180-
}
181-
172+
182173
/**
183174
* Specifies whether this request should add the limit app tracking value
184175
*
@@ -379,7 +370,8 @@ public JSONObject toJSON() {
379370
}
380371
return json;
381372
}
382-
373+
374+
// TODO: Replace with in-memory only ServerRequest objects.
383375
/**
384376
* <p>Converts a {@link JSONObject} object containing keys stored as key-value pairs into
385377
* a {@link ServerRequest}.</p>
@@ -419,13 +411,14 @@ public static ServerRequest fromJSON(JSONObject json, Context context) {
419411
} catch (JSONException e) {
420412
BranchLogger.w("Caught JSONException " + e.getMessage());
421413
}
422-
414+
423415
if (!TextUtils.isEmpty(requestPath)) {
424416
return getExtendedServerRequest(requestPath, post, context, initiatedByClient);
425417
}
426418
return null;
427419
}
428-
420+
421+
// TODO: Replace with in-memory only ServerRequest objects.
429422
/**
430423
* <p>Factory method for creating the specific server requests objects. Creates requests according
431424
* to the request path.</p>
@@ -437,18 +430,17 @@ public static ServerRequest fromJSON(JSONObject json, Context context) {
437430
*/
438431
private static ServerRequest getExtendedServerRequest(String requestPath, JSONObject post, Context context, boolean initiatedByClient) {
439432
ServerRequest extendedReq = null;
440-
433+
441434
if (requestPath.equalsIgnoreCase(Defines.RequestPath.GetURL.getPath())) {
442435
extendedReq = new ServerRequestCreateUrl(Defines.RequestPath.GetURL, post, context);
443436
} else if (requestPath.equalsIgnoreCase(Defines.RequestPath.RegisterInstall.getPath())) {
444437
extendedReq = new ServerRequestRegisterInstall(Defines.RequestPath.RegisterInstall, post, context, initiatedByClient);
445438
} else if (requestPath.equalsIgnoreCase(Defines.RequestPath.RegisterOpen.getPath())) {
446439
extendedReq = new ServerRequestRegisterOpen(Defines.RequestPath.RegisterOpen, post, context, initiatedByClient);
447440
}
448-
449441
return extendedReq;
450442
}
451-
443+
452444
/**
453445
* Updates the google ads parameters. This should be called only from a background thread since it involves GADS method invocation using reflection
454446
* Ensure that when there is a valid GAID/AID, remove the SSAID if it's being used

Branch-SDK/src/main/java/io/branch/referral/ServerRequestCreateUrl.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,6 @@ private String generateLongUrlWithParams(String baseUrl) {
257257
return longUrl;
258258
}
259259

260-
@Override
261-
boolean isPersistable() {
262-
return false; // No need to retrieve create url request from previous session
263-
}
264-
265260
@Override
266261
protected boolean prepareExecuteWithoutTracking() {
267262
// SDK-271 -- Allow creation of short links when tracking is disabled.

Branch-SDK/src/main/java/io/branch/referral/ServerRequestQueue.java

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -83,50 +83,7 @@ static void shutDown() {
8383
private ServerRequestQueue(Context c) {
8484
sharedPref = c.getSharedPreferences("BNC_Server_Request_Queue", Context.MODE_PRIVATE);
8585
editor = sharedPref.edit();
86-
queue = retrieve(c);
87-
}
88-
89-
private void persist() {
90-
try {
91-
JSONArray jsonArr = new JSONArray();
92-
synchronized (reqQueueLockObject) {
93-
for (ServerRequest aQueue : queue) {
94-
if (aQueue.isPersistable()) {
95-
JSONObject json = aQueue.toJSON();
96-
if (json != null) {
97-
jsonArr.put(json);
98-
}
99-
}
100-
}
101-
}
102-
103-
editor.putString(PREF_KEY, jsonArr.toString()).apply();
104-
} catch (Exception ex) {
105-
String msg = ex.getMessage();
106-
BranchLogger.e("Failed to persist queue" + (msg == null ? "" : msg));
107-
}
108-
}
109-
110-
private List<ServerRequest> retrieve(Context context) {
111-
String jsonStr = sharedPref.getString(PREF_KEY, null);
112-
List<ServerRequest> result = Collections.synchronizedList(new LinkedList<ServerRequest>());
113-
synchronized (reqQueueLockObject) {
114-
if (jsonStr != null) {
115-
try {
116-
JSONArray jsonArr = new JSONArray(jsonStr);
117-
for (int i = 0, size = Math.min(jsonArr.length(), MAX_ITEMS); i < size; i++) {
118-
JSONObject json = jsonArr.getJSONObject(i);
119-
ServerRequest req = ServerRequest.fromJSON(json, context);
120-
if (req != null) {
121-
result.add(req);
122-
}
123-
}
124-
} catch (JSONException e) {
125-
BranchLogger.w("Caught JSONException " + e.getMessage());
126-
}
127-
}
128-
}
129-
return result;
86+
queue = Collections.synchronizedList(new LinkedList<ServerRequest>());
13087
}
13188

13289
/**
@@ -154,7 +111,6 @@ void enqueue(ServerRequest request) {
154111
if (getSize() >= MAX_ITEMS) {
155112
queue.remove(1);
156113
}
157-
persist();
158114
}
159115
}
160116
}
@@ -228,7 +184,6 @@ void insert(ServerRequest request, int index) {
228184
index = queue.size();
229185
}
230186
queue.add(index, request);
231-
persist();
232187
} catch (IndexOutOfBoundsException e) {
233188
BranchLogger.e("Caught IndexOutOfBoundsException " + e.getMessage());
234189
}
@@ -250,7 +205,6 @@ public ServerRequest removeAt(int index) {
250205
synchronized (reqQueueLockObject) {
251206
try {
252207
req = queue.remove(index);
253-
persist();
254208
} catch (IndexOutOfBoundsException e) {
255209
BranchLogger.e("Caught IndexOutOfBoundsException " + e.getMessage());
256210
}
@@ -270,7 +224,6 @@ public boolean remove(ServerRequest request) {
270224
synchronized (reqQueueLockObject) {
271225
try {
272226
isRemoved = queue.remove(request);
273-
persist();
274227
} catch (UnsupportedOperationException e) {
275228
BranchLogger.e("Caught UnsupportedOperationException " + e.getMessage());
276229
}
@@ -285,7 +238,6 @@ void clear() {
285238
synchronized (reqQueueLockObject) {
286239
try {
287240
queue.clear();
288-
persist();
289241
} catch (UnsupportedOperationException e) {
290242
BranchLogger.e("Caught UnsupportedOperationException " + e.getMessage());
291243
}

0 commit comments

Comments
 (0)