]> nmode's Git Repositories - signal-cli/commitdiff
Fix overlapping sqlite sessions in migration
authorAsamK <asamk@gmx.de>
Wed, 6 Dec 2023 17:08:35 +0000 (18:08 +0100)
committerAsamK <asamk@gmx.de>
Mon, 11 Dec 2023 17:24:42 +0000 (18:24 +0100)
Fixes #1394

lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientStore.java

index fd2eb5da6a504ee6e76578d2ca5a0b677d372a81..7d0aaf5c95d0a9adfd71ab51c1ecded8451bb365 100644 (file)
@@ -478,10 +478,6 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re
 
     @Override
     public ProfileKey getProfileKey(final RecipientId recipientId) {
-        final var selfRecipientId = resolveRecipient(selfAddressProvider.getSelfAddress());
-        if (recipientId.equals(selfRecipientId)) {
-            return selfProfileKeyProvider.getSelfProfileKey();
-        }
         try (final var connection = database.getConnection()) {
             return getProfileKey(connection, recipientId);
         } catch (SQLException e) {
@@ -662,9 +658,9 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re
             Connection connection, RecipientId recipientId, final ProfileKey profileKey, boolean resetProfile
     ) throws SQLException {
         if (profileKey != null) {
-            final var recipientProfileKey = getProfileKey(recipientId);
+            final var recipientProfileKey = getProfileKey(connection, recipientId);
             if (profileKey.equals(recipientProfileKey)) {
-                final var recipientProfile = getProfile(recipientId);
+                final var recipientProfile = getProfile(connection, recipientId);
                 if (recipientProfile == null || (
                         recipientProfile.getUnidentifiedAccessMode() != Profile.UnidentifiedAccessMode.UNKNOWN
                                 && recipientProfile.getUnidentifiedAccessMode()
@@ -985,6 +981,10 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re
     }
 
     private ProfileKey getProfileKey(final Connection connection, final RecipientId recipientId) throws SQLException {
+        final var selfRecipientId = resolveRecipientLocked(connection, selfAddressProvider.getSelfAddress());
+        if (recipientId.equals(selfRecipientId)) {
+            return selfProfileKeyProvider.getSelfProfileKey();
+        }
         final var sql = (
                 """
                 SELECT r.profile_key