Skip to content

Commit

Permalink
Remove logs more effectively on app start (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzoPrimi authored Jun 25, 2020
1 parent 5d06bc8 commit 41495b6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
@Override
public void onSuccess(ApiMeasurement.Result result) {
measurement.deleteEntryFile(c);
measurement.deleteLogFileAfterAWeek(c);
isInExplorer = true;
}
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.openobservatory.ooniprobe.BuildConfig;
import org.openobservatory.ooniprobe.client.OONIAPIClient;
import org.openobservatory.ooniprobe.client.OONIOrchestraClient;
import org.openobservatory.ooniprobe.model.database.Measurement;
import org.openobservatory.ooniprobe.model.jsonresult.TestKeys;

import java.io.IOException;
Expand Down Expand Up @@ -46,7 +47,7 @@ public class Application extends android.app.Application {
// Code commented to prevent callling API on app start
//if (preferenceManager.canCallDeleteJson())
// Measurement.deleteUploadedJsons(this);

Measurement.deleteOldLogs(this);
}

public OkHttpClient getOkHttpClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public Measurement(Result result, String test_name, String report_id) {
start_time = new java.util.Date();
}

public static Where<Measurement> selectDone() {
return SQLite.select().from(Measurement.class)
.where(Measurement_Table.is_failed.eq(false))
.and(Measurement_Table.is_rerun.eq(false))
.and(Measurement_Table.is_done.eq(true));
}

public static Where<Measurement> selectUploadable() {
// We check on both the report_id and is_uploaded as we
// may have some unuploaded measurements which are marked
Expand Down Expand Up @@ -116,6 +123,17 @@ public static List<Measurement> selectMeasurementsWithJson(Context c) {
return measurementsJson;
}

public static List<Measurement> selectMeasurementsWithLog(Context c) {
Where<Measurement> msmQuery = Measurement.selectDone();
List<Measurement> measurementsLog = new ArrayList<>();
List<Measurement> measurements = msmQuery.queryList();
for (Measurement measurement : measurements){
if (measurement.hasReportFile(c))
measurementsLog.add(measurement);
}
return measurementsLog;
}

public static File getEntryFile(Context c, int measurementId, String test_name) {
return new File(getMeasurementDir(c), measurementId + "_" + test_name + ".json");
}
Expand Down Expand Up @@ -225,7 +243,6 @@ public static void deleteUploadedJsons(Application a){
@Override
public void onSuccess(ApiMeasurement.Result result) {
measurement.deleteEntryFile(a);
measurement.deleteLogFileAfterAWeek(a);
}

@Override
Expand All @@ -237,6 +254,14 @@ public void onError(String msg) {
pm.setLastCalled();
}

public static void deleteOldLogs(Application a){
List<Measurement> measurements = Measurement.selectMeasurementsWithLog(a);
for (int i = 0; i < measurements.size(); i++) {
Measurement measurement = measurements.get(i);
measurement.deleteLogFileAfterAWeek(a);
}
}

public void setReRun(Context c){
this.deleteEntryFile(c);
this.deleteLogFile(c);
Expand Down

0 comments on commit 41495b6

Please sign in to comment.