Browse code

[check_and_repair] ALLOA-19 Fix: make bodies repair retry on missing bodies

Thomas Cataldo authored on 09/07/2019 10:41:08
Showing 1 changed files
... ...
@@ -196,10 +196,10 @@ public class MailboxRecordStore extends AbstractItemValueStore<MailboxRecord> {
196 196
 	public List<ImapBinding> havingBodyVersionLowerThan(final int version) throws SQLException {
197 197
 		final StringBuilder sql = new StringBuilder();
198 198
 		sql.append("SELECT ci.id, mbr.imap_uid, mbr.message_body_guid FROM t_mailbox_record mbr ");
199
-		sql.append("JOIN t_message_body mb ON mbr.message_body_guid = mb.guid ");
200
-		sql.append("JOIN t_container_item ci ON ci.id = mbr.item_id ");
199
+		sql.append("INNER JOIN t_container_item ci ON ci.id = mbr.item_id ");
200
+		sql.append("LEFT JOIN t_message_body mb ON mbr.message_body_guid = mb.guid ");
201 201
 		sql.append("WHERE ci.container_id = ? ");
202
-		sql.append("AND mb.body_version < ? ");
202
+		sql.append("AND (mb.body_version < ? OR mb.guid IS NULL) ");
203 203
 		sql.append("AND (ci.flags::bit(32) & (" + ItemFlag.Deleted.value + ")::bit(32))=0::bit(32) ");
204 204
 		sql.append("AND (mbr.system_flags::bit(32) & (" + InternalFlag.expunged.value + ")::bit(32))=0::bit(32) ");
205 205
 		return select(sql.toString(), rs -> new ImapBinding(), (rs, index, value) -> {