Skip to content

Commit

Permalink
Improve handling of unknown storage records
Browse files Browse the repository at this point in the history
Fixes #1696
  • Loading branch information
AsamK committed Jan 30, 2025
1 parent b8d8413 commit 47d6558
Showing 1 changed file with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,6 @@ private boolean readDataFromStorage(
remoteOnlyRecords.size());
}

final var unknownInserts = processKnownRecords(connection, remoteOnlyRecords);
final var unknownDeletes = idDifference.localOnlyIds()
.stream()
.filter(id -> !KNOWN_TYPES.contains(id.getType()))
.toList();

if (!idDifference.localOnlyIds().isEmpty()) {
final var updated = account.getRecipientStore()
.removeStorageIdsFromLocalOnlyUnregisteredRecipients(connection,
Expand All @@ -228,6 +222,12 @@ private boolean readDataFromStorage(
}
}

final var unknownInserts = processKnownRecords(connection, remoteOnlyRecords);
final var unknownDeletes = idDifference.localOnlyIds()
.stream()
.filter(id -> !KNOWN_TYPES.contains(id.getType()))
.toList();

logger.debug("Storage ids with unknown type: {} inserts, {} deletes",
unknownInserts.size(),
unknownDeletes.size());
Expand Down Expand Up @@ -279,10 +279,22 @@ private boolean writeToStorage(
try (final var connection = account.getAccountDatabase().getConnection()) {
connection.setAutoCommit(false);

final var localStorageIds = getAllLocalStorageIds(connection);
final var idDifference = findIdDifference(remoteManifest.storageIds, localStorageIds);
var localStorageIds = getAllLocalStorageIds(connection);
var idDifference = findIdDifference(remoteManifest.storageIds, localStorageIds);
logger.debug("ID Difference :: {}", idDifference);

final var unknownOnlyLocal = idDifference.localOnlyIds()
.stream()
.filter(id -> !KNOWN_TYPES.contains(id.getType()))
.toList();

if (!unknownOnlyLocal.isEmpty()) {
logger.debug("Storage ids with unknown type: {} to delete", unknownOnlyLocal.size());
account.getUnknownStorageIdStore().deleteUnknownStorageIds(connection, unknownOnlyLocal);
localStorageIds = getAllLocalStorageIds(connection);
idDifference = findIdDifference(remoteManifest.storageIds, localStorageIds);
}

final var remoteDeletes = idDifference.remoteOnlyIds().stream().map(StorageId::getRaw).toList();
final var remoteInserts = buildLocalStorageRecords(connection, idDifference.localOnlyIds());
// TODO check if local storage record proto matches remote, then reset to remote storage_id
Expand Down Expand Up @@ -595,7 +607,7 @@ private static IdDifferenceResult findIdDifference(
final var remote = remoteByRawId.get(rawId);
final var local = localByRawId.get(rawId);

if (remote.getType() != local.getType() && local.getType() != 0) {
if (remote.getType() != local.getType() && KNOWN_TYPES.contains(local.getType())) {
remoteOnlyRawIds.remove(rawId);
localOnlyRawIds.remove(rawId);
hasTypeMismatch = true;
Expand Down

0 comments on commit 47d6558

Please sign in to comment.