feat: extract file text on every attach path and backfill on reindex

- inline and signed uploads queue the text job in their transaction
- the admin form queues it in the save transaction
- detach resyncs the material (its text row goes by cascade)
- bm:materials-reindex backfills missing PDF texts before each sync
This commit is contained in:
Jakub Zych
2026-11-08 20:16:14 +01:00
parent 412821ec56
commit f841e8ed71
11 changed files with 480 additions and 22 deletions

View File

@@ -18,10 +18,12 @@ var (
)
// MaterialIndex keeps the materials search index current once a write
// commits (classes.MaterialIndexer). Its calls never fail the write.
// commits (classes.MaterialIndexer). QueueExtract enqueues the file text job
// inside tx. Its calls never fail the write.
type MaterialIndex interface {
SyncAfterCommit(ctx context.Context, tx *gorm.DB, id uint)
RemoveAfterCommit(ctx context.Context, tx *gorm.DB, id uint)
QueueExtract(ctx context.Context, tx *gorm.DB, id uint)
}
type materialIndexHolder struct{ ix MaterialIndex }
@@ -40,12 +42,17 @@ func installedMaterialIndex() MaterialIndex {
return h.ix
}
// FormAfterCreate syncs the new material once the save transaction commits.
// FormAfterCreate queues the file text job in the save transaction (the
// form's deferred files commit in the same one) and syncs the new material
// once it commits.
func (materialsAdmin) FormAfterCreate(ctx context.Context, model any) error {
return materialAfterCommit(ctx, model, false)
}
// FormAfterUpdate syncs the material once the save transaction commits.
// FormAfterUpdate queues the file text job in the save transaction and
// syncs the material once it commits. A save that added no file queues a
// job that finds no new PDF and only resyncs; a file removed in the form
// leaves the document through the cascade and this sync.
func (materialsAdmin) FormAfterUpdate(ctx context.Context, model any) error {
return materialAfterCommit(ctx, model, false)
}
@@ -70,8 +77,9 @@ func materialAfterCommit(ctx context.Context, model any, remove bool) error {
tx, _ := cabana.TxFromContext(ctx)
if remove {
ix.RemoveAfterCommit(ctx, tx, m.ID)
} else {
ix.SyncAfterCommit(ctx, tx, m.ID)
return nil
}
ix.QueueExtract(ctx, tx, m.ID)
ix.SyncAfterCommit(ctx, tx, m.ID)
return nil
}