fix(paperless): documents.checksum für SHA-256 verbreitern
Build and Push Multi-Platform Images / build-and-push (push) Successful in 28s
Build and Push Multi-Platform Images / build-and-push (push) Successful in 28s
Paperless-NGX ≥ 3.0 liefert original_checksum als SHA-256 (64 Zeichen). Die lokale Spiegeltabelle documents hatte nur varchar(32), wodurch die Nachbearbeitung mit „Data too long for column 'checksum'“ abbrach – nach dem Setzen von Notizen, aber vor Fertig=1. Der Task wurde dadurch jede Minute erneut verarbeitet und erzeugte doppelte Notizen. - documents.checksum auf varchar(64) (Entity + Migration) - Sync der Spiegeltabelle ist nicht mehr fatal: Fehler werden als Warnung geloggt, der Task wird trotzdem abgeschlossen Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4f34855c12
commit
df50470e53
3 files changed
+62
-25
No files matched your search
@@ -5,7 +5,8 @@ export class Document {
|
|||||||
@PrimaryColumn({ type: 'int' })
|
@PrimaryColumn({ type: 'int' })
|
||||||
documentId!: number;
|
documentId!: number;
|
||||||
|
|
||||||
@Column({ type: 'varchar', length: 32, nullable: true })
|
/** SHA-256 des Originals — Paperless ≥ 3.0 liefert 64 Zeichen (vorher MD5) */
|
||||||
|
@Column({ type: 'varchar', length: 64, nullable: true })
|
||||||
checksum!: string | null;
|
checksum!: string | null;
|
||||||
|
|
||||||
@Column({ type: 'varchar', length: 1024, nullable: true })
|
@Column({ type: 'varchar', length: 1024, nullable: true })
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paperless-NGX ≥ 3.0 liefert `original_checksum` als SHA-256 (64 Zeichen).
|
||||||
|
* Die lokale Spiegeltabelle `documents` hatte nur Platz für MD5 (32 Zeichen),
|
||||||
|
* wodurch die Nachbearbeitung neuer Dokumente mit „Data too long“ abbrach.
|
||||||
|
*/
|
||||||
|
export class DocumentChecksumSha2561793600000000 implements MigrationInterface {
|
||||||
|
name = 'DocumentChecksumSha2561793600000000';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE \`documents\`
|
||||||
|
MODIFY \`checksum\` varchar(64) NULL DEFAULT NULL
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
// SHA-256-Werte passen nicht mehr in 32 Zeichen und werden verworfen.
|
||||||
|
await queryRunner.query(`
|
||||||
|
UPDATE \`documents\` SET \`checksum\` = NULL WHERE LENGTH(\`checksum\`) > 32
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE \`documents\`
|
||||||
|
MODIFY \`checksum\` varchar(32) NULL DEFAULT NULL
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -375,34 +375,42 @@ export class PaperlessTaskProcessorService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync local Documents table
|
// Sync local Documents table — nur Spiegel; ein Fehler hier darf den Task
|
||||||
this.logger.log(
|
// nicht offen lassen, sonst würde er jede Minute erneut nachbearbeitet
|
||||||
`[Postprocessing] Task ${t.TaskId} - Synchronisiere lokale Documents-Tabelle`,
|
// (doppelte Notizen in Paperless).
|
||||||
);
|
try {
|
||||||
const metadata = await this.paperlessService.getDocumentMetadata(
|
|
||||||
document.id,
|
|
||||||
);
|
|
||||||
let localDoc = await this.documentRepo.findOne({
|
|
||||||
where: { documentId: document.id },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!localDoc) {
|
|
||||||
this.logger.log(
|
this.logger.log(
|
||||||
`[Postprocessing] Task ${t.TaskId} - Erstelle neuen lokalen Dokument-Eintrag`,
|
`[Postprocessing] Task ${t.TaskId} - Synchronisiere lokale Documents-Tabelle`,
|
||||||
);
|
);
|
||||||
localDoc = this.documentRepo.create({
|
const metadata = await this.paperlessService.getDocumentMetadata(
|
||||||
documentId: document.id,
|
document.id,
|
||||||
checksum: metadata.original_checksum,
|
);
|
||||||
filename: metadata.original_filename,
|
let localDoc = await this.documentRepo.findOne({
|
||||||
|
where: { documentId: document.id },
|
||||||
});
|
});
|
||||||
await this.documentRepo.save(localDoc);
|
|
||||||
} else {
|
if (!localDoc) {
|
||||||
this.logger.log(
|
this.logger.log(
|
||||||
`[Postprocessing] Task ${t.TaskId} - Aktualisiere bestehenden lokalen Dokument-Eintrag`,
|
`[Postprocessing] Task ${t.TaskId} - Erstelle neuen lokalen Dokument-Eintrag`,
|
||||||
|
);
|
||||||
|
localDoc = this.documentRepo.create({
|
||||||
|
documentId: document.id,
|
||||||
|
checksum: metadata.original_checksum,
|
||||||
|
filename: metadata.original_filename,
|
||||||
|
});
|
||||||
|
await this.documentRepo.save(localDoc);
|
||||||
|
} else {
|
||||||
|
this.logger.log(
|
||||||
|
`[Postprocessing] Task ${t.TaskId} - Aktualisiere bestehenden lokalen Dokument-Eintrag`,
|
||||||
|
);
|
||||||
|
localDoc.checksum = metadata.original_checksum;
|
||||||
|
localDoc.filename = metadata.original_filename;
|
||||||
|
await this.documentRepo.save(localDoc);
|
||||||
|
}
|
||||||
|
} catch (syncError) {
|
||||||
|
this.logger.warn(
|
||||||
|
`[Postprocessing] Task ${t.TaskId} - Lokale Documents-Tabelle nicht synchronisiert: ${syncError.message}`,
|
||||||
);
|
);
|
||||||
localDoc.checksum = metadata.original_checksum;
|
|
||||||
localDoc.filename = metadata.original_filename;
|
|
||||||
await this.documentRepo.save(localDoc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Task status
|
// Update Task status
|
||||||
|
|||||||
Reference in new issue
Block a user