Improve cache deletion

This commit is contained in:
tom79 2019-07-22 12:27:46 +02:00
parent d41cc7d2ee
commit f0f758cdc4
2 changed files with 19 additions and 4 deletions

View File

@ -206,6 +206,8 @@ import app.fedilab.android.client.Entities.Version;
import app.fedilab.android.client.Tls12SocketFactory;
import app.fedilab.android.fragments.DisplayMutedInstanceFragment;
import app.fedilab.android.sqlite.DomainBlockDAO;
import app.fedilab.android.sqlite.StatusCacheDAO;
import app.fedilab.android.sqlite.TimelineCacheDAO;
import es.dmoral.toasty.Toasty;
import app.fedilab.android.BuildConfig;
import app.fedilab.android.R;
@ -2065,14 +2067,17 @@ public class Helper {
if( directory == null || directory.length() == 0 )
return -1;
for (File file : directory.listFiles()) {
if (file.isFile())
if (file.isFile()){
try {
length += file.length();
}catch (NullPointerException e){
} catch (NullPointerException e) {
return -1;
}
else
length += cacheSize(file);
}else {
if( !file.getName().equals("databases") && !file.getName().equals("shared_prefs")) {
length += cacheSize(file);
}
}
}
return length;
}
@ -3858,6 +3863,11 @@ public class Helper {
if (dir.isDirectory()) {
Helper.deleteDir(dir);
}
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new StatusCacheDAO(contextReference.get(), db).removeDuplicate();
Date date = new Date( System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1));
String dateString = Helper.dateToString(date);
new TimelineCacheDAO(contextReference.get(), db).removeAfterDate(dateString);
} catch (Exception ignored) {
}
}

View File

@ -189,6 +189,11 @@ public class StatusCacheDAO {
return db.delete(Sqlite.TABLE_STATUSES_CACHE, Sqlite.COL_CACHED_ACTION + " = \""+ cacheType +"\" AND " + Sqlite.COL_STATUS_ID + " = \"" + status.getId() + "\" AND " + Sqlite.COL_INSTANCE + " = \"" + instance + "\" AND " + Sqlite.COL_USER_ID + " = '" + userId+ "'", null);
}
public void removeDuplicate(){
db.execSQL("DELETE FROM "+Sqlite.TABLE_STATUSES_CACHE+" WHERE "+Sqlite.COL_ID+" NOT IN (SELECT MIN("+Sqlite.COL_ID+") FROM "+Sqlite.TABLE_STATUSES_CACHE+" GROUP BY "+Sqlite.COL_STATUS_ID+","+Sqlite.COL_INSTANCE+")");
}
/***
* Remove stored status
* @return int