Prevent crash when receiving already migrated group v1 from storage

Fixes #1471
This commit is contained in:
AsamK 2024-02-25 19:41:10 +01:00
parent 6c44662496
commit 57164ad7fb
2 changed files with 25 additions and 19 deletions

View file

@ -229,22 +229,26 @@ public class GroupStore {
public GroupInfoV1 getOrCreateGroupV1(GroupIdV1 groupId) { public GroupInfoV1 getOrCreateGroupV1(GroupIdV1 groupId) {
try (final var connection = database.getConnection()) { try (final var connection = database.getConnection()) {
var group = getGroup(connection, groupId); return getOrCreateGroupV1(connection, groupId);
if (group != null) {
return group;
}
if (getGroupV2ByV1Id(connection, groupId) == null) {
return new GroupInfoV1(groupId);
}
return null;
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException("Failed read from group store", e); throw new RuntimeException("Failed read from group store", e);
} }
} }
public GroupInfoV1 getOrCreateGroupV1(final Connection connection, final GroupIdV1 groupId) throws SQLException {
var group = getGroup(connection, groupId);
if (group != null) {
return group;
}
if (getGroupV2ByV1Id(connection, groupId) == null) {
return new GroupInfoV1(groupId);
}
return null;
}
public GroupInfoV2 getGroupOrPartialMigrate( public GroupInfoV2 getGroupOrPartialMigrate(
Connection connection, final GroupMasterKey groupMasterKey Connection connection, final GroupMasterKey groupMasterKey
) throws SQLException { ) throws SQLException {

View file

@ -112,14 +112,16 @@ public final class GroupV1RecordProcessor extends DefaultStorageRecordProcessor<
final var groupV1Record = update.newRecord(); final var groupV1Record = update.newRecord();
final var groupIdV1 = GroupId.v1(groupV1Record.getGroupId()); final var groupIdV1 = GroupId.v1(groupV1Record.getGroupId());
final var group = account.getGroupStore().getGroup(connection, groupIdV1); final var group = account.getGroupStore().getOrCreateGroupV1(connection, groupIdV1);
group.setBlocked(groupV1Record.isBlocked()); if (group != null) {
account.getGroupStore().updateGroup(connection, group); group.setBlocked(groupV1Record.isBlocked());
account.getGroupStore() account.getGroupStore().updateGroup(connection, group);
.storeStorageRecord(connection, account.getGroupStore()
group.getGroupId(), .storeStorageRecord(connection,
groupV1Record.getId(), group.getGroupId(),
groupV1Record.toProto().encode()); groupV1Record.getId(),
groupV1Record.toProto().encode());
}
} }
@Override @Override