Skip to content

Commit a86cd3b

Browse files
authored
refactor: Remove unused session history upload code (#507)
1 parent 687e623 commit a86cd3b

File tree

9 files changed

+22
-208
lines changed

9 files changed

+22
-208
lines changed

android-core/src/androidTest/kotlin/com.mparticle/internal/BatchSessionInfoTest.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import com.mparticle.MParticle
66
import com.mparticle.MParticleOptions
77
import com.mparticle.networking.Matcher
88
import com.mparticle.testutils.BaseCleanStartedEachTest
9-
import org.json.JSONObject
109
import org.junit.Test
1110
import kotlin.test.assertEquals
1211
import kotlin.test.assertNotEquals
@@ -19,16 +18,6 @@ class BatchSessionInfoTest : BaseCleanStartedEachTest() {
1918
return builder.logLevel(MParticle.LogLevel.INFO)
2019
}
2120

22-
override fun beforeSetup() {
23-
// the condition described in the test only happened when `sessionHistory` is false,
24-
// so set config to return `sessionHistory` == false
25-
mServer.setupConfigResponse(
26-
JSONObject()
27-
.put(ConfigManager.KEY_INCLUDE_SESSION_HISTORY, false)
28-
.toString()
29-
)
30-
}
31-
3221
/**
3322
* This test is in response to a bug where, when many messages (> 1 batch worth)
3423
* are uploaded with for a Session other than the current Session, batches after the first

android-core/src/main/java/com/mparticle/internal/ConfigManager.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public class ConfigManager {
5858
public static final String VALUE_APP_DEFINED = "appdefined";
5959
public static final String VALUE_CUE_CATCH = "forcecatch";
6060
public static final String PREFERENCES_FILE = "mp_preferences";
61-
public static final String KEY_INCLUDE_SESSION_HISTORY = "inhd";
6261
private static final String KEY_DEVICE_PERFORMANCE_METRICS_DISABLED = "dpmd";
6362
public static final String WORKSPACE_TOKEN = "wst";
6463
static final String ALIAS_MAX_WINDOW = "alias_max_window";
@@ -98,7 +97,6 @@ public class ConfigManager {
9897
private long mInfluenceOpenTimeout = 3600 * 1000;
9998
private JSONArray mTriggerMessageMatches, mTriggerMessageHashes = null;
10099
private ExceptionHandler mExHandler;
101-
private boolean mIncludeSessionHistory = false;
102100
private JSONObject mCurrentCookies;
103101
private String mDataplanId;
104102
private Integer mDataplanVersion;
@@ -453,7 +451,6 @@ private synchronized void updateCoreConfig(JSONObject responseJSON, boolean newC
453451
mInfluenceOpenTimeout = 30 * 60 * 1000;
454452
}
455453

456-
mIncludeSessionHistory = responseJSON.optBoolean(KEY_INCLUDE_SESSION_HISTORY, true);
457454
if (responseJSON.has(KEY_DEVICE_PERFORMANCE_METRICS_DISABLED)) {
458455
MessageManager.devicePerformanceMetricsDisabled = responseJSON.optBoolean(KEY_DEVICE_PERFORMANCE_METRICS_DISABLED, false);
459456
}
@@ -504,10 +501,6 @@ public String getActiveModuleIds() {
504501
}
505502
}
506503

507-
public boolean getIncludeSessionHistory() {
508-
return mIncludeSessionHistory;
509-
}
510-
511504
/**
512505
* When the Config manager starts up, we don't want to enable everything immediately to save on app-load time.
513506
* This method will be called from a background thread after startup is already complete.

android-core/src/main/java/com/mparticle/internal/Constants.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ public interface MessageKey {
338338
String ERROR_SESSION_COUNT = "sn";
339339
// uploading
340340
String MESSAGES = "msgs";
341-
String HISTORY = "sh";
342341
String REPORTING = "fsr";
343342
String URL = "u";
344343
String METHOD = "m";

android-core/src/main/java/com/mparticle/internal/MParticleApiClientImpl.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,6 @@ private void logUpload(String message) {
343343
for (int i = 0; i < messages.length(); i++) {
344344
Logger.verbose("Message type: " + ((JSONObject) messages.get(i)).getString(Constants.MessageKey.TYPE));
345345
}
346-
} else if (messageJson.has(Constants.MessageKey.HISTORY)) {
347-
JSONArray messages = messageJson.getJSONArray(Constants.MessageKey.HISTORY);
348-
Logger.verbose("Uploading session history batch...");
349-
for (int i = 0; i < messages.length(); i++) {
350-
Logger.verbose("Message type: " + ((JSONObject) messages.get(i)).getString(Constants.MessageKey.TYPE) + " SID: " + ((JSONObject) messages.get(i)).optString(Constants.MessageKey.SESSION_ID));
351-
}
352346
}
353347
} catch (JSONException jse) {
354348

android-core/src/main/java/com/mparticle/internal/MessageBatch.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,6 @@ public void addDataplanContext(String dataplanId, Integer dataplanVersion) throw
100100
}
101101
}
102102

103-
public void addSessionHistoryMessage(JSONObject message) {
104-
try {
105-
if (!has(Constants.MessageKey.HISTORY)) {
106-
put(Constants.MessageKey.HISTORY, new JSONArray());
107-
}
108-
getJSONArray(Constants.MessageKey.HISTORY).put(message);
109-
} catch (JSONException ignored) {
110-
}
111-
}
112-
113103
public void addMessage(JSONObject message) {
114104
try {
115105
if (!has(Constants.MessageKey.MESSAGES)) {
@@ -160,14 +150,6 @@ public JSONObject getDeviceInfo() {
160150
}
161151
}
162152

163-
public JSONArray getSessionHistoryMessages() {
164-
try {
165-
return getJSONArray(Constants.MessageKey.HISTORY);
166-
} catch (JSONException e) {
167-
return null;
168-
}
169-
}
170-
171153
public JSONArray getMessages() {
172154
try {
173155
return getJSONArray(Constants.MessageKey.MESSAGES);

android-core/src/main/java/com/mparticle/internal/UploadHandler.java

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ public class UploadHandler extends BaseHandler {
3939
* Message used to trigger the primary upload logic - will upload all non-history batches that are ready to go.
4040
*/
4141
public static final int UPLOAD_MESSAGES = 1;
42-
/**
43-
* Message that triggers much of the same logic as above, but is specifically for session-history. Typically, the SDK will upload all messages
44-
* in a given batch that are ready for upload. But, some service-providers such as Flurry need to be sent all of the session information at once
45-
* With *history*, the SDK will package all of the messages that occur in a particular session.
46-
*/
47-
public static final int UPLOAD_HISTORY = 3;
4842
/**
4943
* Trigger a configuration update out of band from a typical upload.
5044
*/
@@ -137,25 +131,15 @@ public void handleMessageImpl(Message msg) {
137131
if (isNetworkConnected) {
138132
if (uploadInterval > 0 || msg.arg1 == 1) {
139133
while (mParticleDBManager.hasMessagesForUpload()) {
140-
prepareMessageUploads(false);
141-
}
142-
boolean needsHistory = upload(false);
143-
if (needsHistory) {
144-
this.sendEmpty(UPLOAD_HISTORY);
134+
prepareMessageUploads();
145135
}
136+
upload();
146137
}
147138
}
148139
if (mAppStateManager.getSession().isActive() && uploadInterval > 0 && msg.arg1 == 0) {
149140
this.sendEmptyDelayed(UPLOAD_MESSAGES, uploadInterval);
150141
}
151142
break;
152-
case UPLOAD_HISTORY:
153-
removeMessage(UPLOAD_HISTORY);
154-
prepareMessageUploads(true);
155-
if (isNetworkConnected) {
156-
upload(true);
157-
}
158-
break;
159143
}
160144
} catch (MParticleApiClientImpl.MPConfigException e) {
161145
Logger.error("Bad API request - is the correct API key and secret configured?");
@@ -175,7 +159,7 @@ public void handleMessageImpl(Message msg) {
175159
* - persist all of the resulting upload batch objects
176160
* - mark the messages as having been uploaded.
177161
*/
178-
protected void prepareMessageUploads(boolean history) throws Exception {
162+
protected void prepareMessageUploads() throws Exception {
179163
String currentSessionId = mAppStateManager.getSession().mSessionID;
180164
long remainingHeap = MPUtility.getRemainingHeapInBytes();
181165
if (remainingHeap < Constants.LIMIT_MAX_UPLOAD_SIZE) {
@@ -186,18 +170,9 @@ protected void prepareMessageUploads(boolean history) throws Exception {
186170
if (instance == null) {
187171
return;
188172
}
189-
final boolean sessionHistoryEnabled = instance.Internal().getConfigManager().getIncludeSessionHistory();
190173
try {
191174
mParticleDBManager.cleanupMessages();
192-
if (history && !sessionHistoryEnabled) {
193-
mParticleDBManager.deleteMessagesAndSessions(currentSessionId);
194-
return;
195-
}
196-
if (history) {
197-
mParticleDBManager.createSessionHistoryUploadMessage(mConfigManager, mMessageManager.getDeviceAttributes(), currentSessionId);
198-
} else {
199-
mParticleDBManager.createMessagesForUploadMessage(mConfigManager, mMessageManager.getDeviceAttributes(), currentSessionId, sessionHistoryEnabled);
200-
}
175+
mParticleDBManager.createMessagesForUploadMessage(mConfigManager, mMessageManager.getDeviceAttributes(), currentSessionId);
201176
} catch (Exception e) {
202177
Logger.verbose("Error preparing batch upload in mParticle DB: " + e.getMessage());
203178
}
@@ -208,34 +183,20 @@ protected void prepareMessageUploads(boolean history) throws Exception {
208183
/**
209184
* This method is responsible for looking for batches that are ready to be uploaded, and uploading them.
210185
*/
211-
protected boolean upload(boolean history) {
186+
protected void upload() {
212187
mParticleDBManager.cleanupUploadMessages();
213-
boolean processingSessionEnd = false;
214188
try {
215189
List<MParticleDBManager.ReadyUpload> readyUploads = mParticleDBManager.getReadyUploads();
216190
if (readyUploads.size() > 0) {
217191
mApiClient.fetchConfig();
218192
}
219-
final boolean includeSessionHistory = mConfigManager.getIncludeSessionHistory();
220193
for (MParticleDBManager.ReadyUpload readyUpload : readyUploads) {
221-
//This case actually shouldn't be needed anymore except for upgrade scenarios.
222-
//As of version 4.9.0, upload batches for session history shouldn't even be created.
223-
if (history && !includeSessionHistory) {
224-
mParticleDBManager.deleteUpload(readyUpload.getId());
194+
String message = readyUpload.getMessage();
195+
InternalListenerManager.getListener().onCompositeObjects(readyUpload, message);
196+
if (readyUpload.isAliasRequest()) {
197+
uploadAliasRequest(readyUpload.getId(), message);
225198
} else {
226-
if (!history) {
227-
// If message is the MessageType.SESSION_END, then remember so the session history can be triggered.
228-
if (!processingSessionEnd && readyUpload.getMessage().contains(containsClause)) {
229-
processingSessionEnd = true;
230-
}
231-
}
232-
String message = readyUpload.getMessage();
233-
InternalListenerManager.getListener().onCompositeObjects(readyUpload, message);
234-
if (readyUpload.isAliasRequest()) {
235-
uploadAliasRequest(readyUpload.getId(), message);
236-
} else {
237-
uploadMessage(readyUpload.getId(), message);
238-
}
199+
uploadMessage(readyUpload.getId(), message);
239200
}
240201
}
241202
} catch (MParticleApiClientImpl.MPThrottleException e) {
@@ -246,7 +207,6 @@ protected boolean upload(boolean history) {
246207
} catch (Exception e) {
247208
Logger.error(e, "Error processing batch uploads in mParticle DB.");
248209
}
249-
return processingSessionEnd;
250210
}
251211

252212
void uploadMessage(int id, String message) throws IOException, MParticleApiClientImpl.MPThrottleException {

android-core/src/main/java/com/mparticle/internal/database/services/MParticleDBManager.java

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -136,35 +136,12 @@ public interface MessageListener {
136136
* Prepare Messages for Upload.
137137
*/
138138

139-
public void createSessionHistoryUploadMessage(ConfigManager configManager, DeviceAttributes deviceAttributes, String currentSessionId) throws JSONException {
140-
MPDatabase db = getDatabase();
141-
db.beginTransaction();
142-
try {
143-
List<MessageService.ReadyMessage> readyMessages = MessageService.getSessionHistory(db, currentSessionId);
144-
if (readyMessages.size() <= 0) {
145-
db.setTransactionSuccessful();
146-
return;
147-
}
148-
149-
HashMap<BatchId, MessageBatch> uploadMessagesByBatchId = getUploadMessageByBatchIdMap(readyMessages, db, configManager, true);
150-
151-
List<JSONObject> deviceInfos = SessionService.processSessions(db, uploadMessagesByBatchId);
152-
for (JSONObject deviceInfo : deviceInfos) {
153-
deviceAttributes.updateDeviceInfo(mContext, deviceInfo);
154-
}
155-
createUploads(uploadMessagesByBatchId, db, deviceAttributes, configManager, currentSessionId, true);
156-
db.setTransactionSuccessful();
157-
} finally {
158-
db.endTransaction();
159-
}
160-
}
161-
162139
public boolean hasMessagesForUpload() {
163140
MPDatabase db = getDatabase();
164141
return MessageService.hasMessagesForUpload(db);
165142
}
166143

167-
public void createMessagesForUploadMessage(ConfigManager configManager, DeviceAttributes deviceAttributes, String currentSessionId, boolean sessionHistoryEnabled) throws JSONException {
144+
public void createMessagesForUploadMessage(ConfigManager configManager, DeviceAttributes deviceAttributes, String currentSessionId) throws JSONException {
168145
MPDatabase db = getDatabase();
169146
db.beginTransaction();
170147
try {
@@ -173,7 +150,7 @@ public void createMessagesForUploadMessage(ConfigManager configManager, DeviceAt
173150
db.setTransactionSuccessful();
174151
return;
175152
}
176-
HashMap<BatchId, MessageBatch> uploadMessagesByBatchId = getUploadMessageByBatchIdMap(readyMessages, db, configManager, false, sessionHistoryEnabled);
153+
HashMap<BatchId, MessageBatch> uploadMessagesByBatchId = getUploadMessageByBatchIdMap(readyMessages, db, configManager, false);
177154

178155
List<ReportingService.ReportingMessage> reportingMessages = ReportingService.getReportingMessagesForUpload(db);
179156
for (ReportingService.ReportingMessage reportingMessage : reportingMessages) {
@@ -209,7 +186,7 @@ public void createMessagesForUploadMessage(ConfigManager configManager, DeviceAt
209186
for (JSONObject deviceInfo : deviceInfos) {
210187
deviceAttributes.updateDeviceInfo(mContext, deviceInfo);
211188
}
212-
createUploads(uploadMessagesByBatchId, db, deviceAttributes, configManager, currentSessionId, false, sessionHistoryEnabled);
189+
createUploads(uploadMessagesByBatchId, db, deviceAttributes, configManager, currentSessionId);
213190
db.setTransactionSuccessful();
214191
} finally {
215192
db.endTransaction();
@@ -228,11 +205,11 @@ public void deleteMessagesAndSessions(String currentSessionId) {
228205
}
229206
}
230207

231-
private HashMap<BatchId, MessageBatch> getUploadMessageByBatchIdMap(List<MessageService.ReadyMessage> readyMessages, MPDatabase db, ConfigManager configManager, boolean isHistory) throws JSONException {
232-
return getUploadMessageByBatchIdMap(readyMessages, db, configManager, isHistory, false);
208+
private HashMap<BatchId, MessageBatch> getUploadMessageByBatchIdMap(List<MessageService.ReadyMessage> readyMessages, MPDatabase db, ConfigManager configManager) throws JSONException {
209+
return getUploadMessageByBatchIdMap(readyMessages, db, configManager, false);
233210
}
234211

235-
private HashMap<BatchId, MessageBatch> getUploadMessageByBatchIdMap(List<MessageService.ReadyMessage> readyMessages, MPDatabase db, ConfigManager configManager, boolean isHistory, boolean markAsUpload) throws JSONException {
212+
private HashMap<BatchId, MessageBatch> getUploadMessageByBatchIdMap(List<MessageService.ReadyMessage> readyMessages, MPDatabase db, ConfigManager configManager, boolean markAsUpload) throws JSONException {
236213
HashMap<BatchId, MessageBatch> uploadMessagesByBatchId = new HashMap<BatchId, MessageBatch>();
237214
int highestUploadedMessageId = -1;
238215
for (MessageService.ReadyMessage readyMessage : readyMessages) {
@@ -247,11 +224,7 @@ private HashMap<BatchId, MessageBatch> getUploadMessageByBatchIdMap(List<Message
247224
if (messageLength + uploadMessage.getMessageLengthBytes() > Constants.LIMIT_MAX_UPLOAD_SIZE) {
248225
break;
249226
}
250-
if (isHistory) {
251-
uploadMessage.addSessionHistoryMessage(msgObject);
252-
} else {
253-
uploadMessage.addMessage(msgObject);
254-
}
227+
uploadMessage.addMessage(msgObject);
255228
InternalListenerManager.getListener().onCompositeObjects(readyMessage, uploadMessage);
256229
uploadMessage.incrementMessageLengthBytes(messageLength);
257230
highestUploadedMessageId = readyMessage.getMessageId();
@@ -266,11 +239,7 @@ private HashMap<BatchId, MessageBatch> getUploadMessageByBatchIdMap(List<Message
266239
return uploadMessagesByBatchId;
267240
}
268241

269-
private void createUploads(Map<BatchId, MessageBatch> uploadMessagesByBatchId, MPDatabase db, DeviceAttributes deviceAttributes, ConfigManager configManager, String currentSessionId, boolean historyMessages) {
270-
createUploads(uploadMessagesByBatchId, db, deviceAttributes, configManager, currentSessionId, historyMessages, false);
271-
}
272-
273-
private void createUploads(Map<BatchId, MessageBatch> uploadMessagesByBatchId, MPDatabase db, DeviceAttributes deviceAttributes, ConfigManager configManager, String currentSessionId, boolean historyMessages, boolean sessionHistoryEnabled) {
242+
private void createUploads(Map<BatchId, MessageBatch> uploadMessagesByBatchId, MPDatabase db, DeviceAttributes deviceAttributes, ConfigManager configManager, String currentSessionId) {
274243
for (Map.Entry<BatchId, MessageBatch> messageBatchEntry : uploadMessagesByBatchId.entrySet()) {
275244
BatchId batchId = messageBatchEntry.getKey();
276245
MessageBatch uploadMessage = messageBatchEntry.getValue();
@@ -284,12 +253,7 @@ private void createUploads(Map<BatchId, MessageBatch> uploadMessagesByBatchId, M
284253
if (uploadMessage.getDeviceInfo() == null || sessionId.equals(currentSessionId)) {
285254
uploadMessage.setDeviceInfo(deviceAttributes.getDeviceInfo(mContext));
286255
}
287-
JSONArray messages;
288-
if (historyMessages) {
289-
messages = uploadMessage.getSessionHistoryMessages();
290-
} else {
291-
messages = uploadMessage.getMessages();
292-
}
256+
JSONArray messages = uploadMessage.getMessages();
293257
JSONArray identities = findIdentityState(configManager, messages, batchId.getMpid());
294258
uploadMessage.setIdentities(identities);
295259
JSONObject userAttributes = findUserAttributeState(messages, batchId.getMpid());
@@ -311,12 +275,7 @@ private void createUploads(Map<BatchId, MessageBatch> uploadMessagesByBatchId, M
311275
}
312276

313277
UploadService.insertUpload(db, batch, configManager.getApiKey());
314-
//if this was to process session history, or
315-
//if we're never going to process history AND
316-
//this batch contains a previous session, then delete the session.
317-
if (!historyMessages && !sessionHistoryEnabled) {
318-
cleanSessions(currentSessionId);
319-
}
278+
cleanSessions(currentSessionId);
320279
}
321280
}
322281
}

android-core/src/test/kotlin/com/mparticle/internal/ConfigManagerTest.kt

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -459,28 +459,6 @@ class ConfigManagerTest {
459459
Assert.assertNull(manager.integrationAttributes)
460460
}
461461

462-
@Test
463-
@Throws(Exception::class)
464-
fun testDefaultIncludeSessionHistory() {
465-
Assert.assertTrue(manager.includeSessionHistory)
466-
}
467-
468-
@Test
469-
@Throws(Exception::class)
470-
fun testIncludeSessionHistoryUpdateFromServer() {
471-
Assert.assertTrue(manager.includeSessionHistory)
472-
val config = JSONObject()
473-
config.put("inhd", false)
474-
manager.updateConfig(config)
475-
Assert.assertFalse(manager.includeSessionHistory)
476-
config.put("inhd", true)
477-
manager.updateConfig(config)
478-
Assert.assertTrue(manager.includeSessionHistory)
479-
config.put("inhd", "false")
480-
manager.updateConfig(config)
481-
Assert.assertFalse(manager.includeSessionHistory)
482-
}
483-
484462
@Test
485463
@Throws(Exception::class)
486464
fun testSaveUserIdentityJson() {

0 commit comments

Comments
 (0)