Cloud sync: triggers for account/identity last modified time

This commit is contained in:
M66B 2023-01-19 22:00:37 +01:00
parent 3aab01aee3
commit d9dd4843bb
4 changed files with 37 additions and 5 deletions

View File

@ -258,7 +258,8 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
tvLast.setText(context.getString(R.string.title_last_connected,
(account.last_connected == null ? "-" : DTF.format(account.last_connected)) +
(BuildConfig.DEBUG ?
" " + account.poll_interval +
"/" + (account.last_modified == null ? "-" : DTF.format(account.last_modified)) +
" " + account.poll_interval +
"/" + account.keep_alive_ok +
"/" + account.keep_alive_failed +
"/" + account.keep_alive_succeeded : "")));

View File

@ -137,7 +137,7 @@ public class CloudSync {
receiveRemoteData(context, user, password, lrevision, jstatus);
} else
receiveRemoteData(context, user, password, lrevision, jstatus);
else if (BuildConfig.DEBUG)
else if (BuildConfig.DEBUG && false)
receiveRemoteData(context, user, password, lrevision - 1, jstatus);
} else
throw new IllegalArgumentException("Expected one status item");
@ -169,8 +169,11 @@ public class CloudSync {
boolean apassword = (account.auth_type == ServiceAuthenticator.AUTH_TYPE_PASSWORD);
if (aexisting == null ||
!EntityAccount.areEqual(account, aexisting, apassword, false))
!EntityAccount.areEqual(account, aexisting, apassword, false)) {
Helper.writeText(afile, account.toJSON().toString());
if (account.last_modified != null)
afile.setLastModified(account.last_modified);
}
long atime = afile.lastModified();
if (last == null || atime > last)
@ -189,8 +192,11 @@ public class CloudSync {
boolean ipassword = (account.auth_type == ServiceAuthenticator.AUTH_TYPE_PASSWORD);
if (iexisting == null ||
EntityIdentity.areEqual(identity, iexisting, ipassword, false))
!EntityIdentity.areEqual(identity, iexisting, ipassword, false)) {
Helper.writeText(ifile, identity.toJSON().toString());
if (identity.last_modified != null)
ifile.setLastModified(identity.last_modified);
}
long itime = ifile.lastModified();
if (itime > last)

View File

@ -139,6 +139,7 @@ public abstract class DB extends RoomDatabase {
"cache_size", "cache_spill",
"soft_heap_limit", "hard_heap_limit", "mmap_size",
"foreign_keys", "auto_vacuum",
"recursive_triggers",
"compile_options"
));
@ -470,6 +471,11 @@ public abstract class DB extends RoomDatabase {
cursor.moveToNext(); // required
}
Log.i("Set PRAGMA recursive_triggers=off");
try (Cursor cursor = db.query("PRAGMA recursive_triggers=off;")) {
cursor.moveToNext(); // required
}
// https://www.sqlite.org/pragma.html
for (String pragma : DB_PRAGMAS)
if (!"compile_options".equals(pragma) || BuildConfig.DEBUG)
@ -486,6 +492,9 @@ public abstract class DB extends RoomDatabase {
if (BuildConfig.DEBUG && false) {
db.execSQL("DROP TRIGGER IF EXISTS `attachment_insert`");
db.execSQL("DROP TRIGGER IF EXISTS `attachment_delete`");
db.execSQL("DROP TRIGGER IF EXISTS `account_update`");
db.execSQL("DROP TRIGGER IF EXISTS `identity_update`");
}
createTriggers(db);
@ -547,6 +556,20 @@ public abstract class DB extends RoomDatabase {
" AND OLD.encryption IS NULL" +
" AND NOT ((OLD.disposition = 'inline' OR (OLD.related IS NOT 0 AND OLD.cid IS NOT NULL)) AND OLD.type IN (" + images + "));" +
" END");
db.execSQL("CREATE TRIGGER IF NOT EXISTS account_update" +
" AFTER UPDATE ON account" +
" BEGIN" +
" UPDATE account SET last_modified = strftime('%s') * 1000" +
" WHERE (NEW.auth_type = " + AUTH_TYPE_PASSWORD + " OR OLD.password = NEW.password);" +
" END");
db.execSQL("CREATE TRIGGER IF NOT EXISTS identity_update" +
" AFTER UPDATE ON identity" +
" BEGIN" +
" UPDATE identity SET last_modified = strftime('%s') * 1000" +
" WHERE (NEW.auth_type = " + AUTH_TYPE_PASSWORD + " OR OLD.password = NEW.password);" +
" END");
}
private static void logMigration(int startVersion, int endVersion) {

View File

@ -475,7 +475,9 @@ public class EntityAccount extends EntityOrder implements Serializable {
(!state || Objects.equals(a1.max_size, other.max_size)) &&
(!state || Objects.equals(a1.capabilities, other.capabilities)) &&
(!state || Objects.equals(a1.capability_idle, other.capability_idle)) &&
(!state || Objects.equals(a1.capability_utf8, other.capability_utf8)));
(!state || Objects.equals(a1.capability_utf8, other.capability_utf8)) &&
(!state || Objects.equals(a1.capability_uidl, other.capability_uidl)) &&
(!state || Objects.equals(a1.last_modified, other.last_modified)));
}
@Override