(ctx context.Context)
| 170 | } |
| 171 | |
| 172 | func (t *FullTextCopyTask) Do(ctx context.Context) (task.Status, error) { |
| 173 | dep := dependency.FromContext(ctx) |
| 174 | l := dep.Logger() |
| 175 | fm := NewFileManager(dep, inventory.UserFromContext(ctx)).(*manager) |
| 176 | |
| 177 | if !fm.settings.FTSEnabled(ctx) { |
| 178 | l.Debug("FTS disabled, skipping full text copy task.") |
| 179 | return task.StatusCompleted, nil |
| 180 | } |
| 181 | |
| 182 | var state FullTextCopyTaskState |
| 183 | if err := json.Unmarshal([]byte(t.State()), &state); err != nil { |
| 184 | return task.StatusError, fmt.Errorf("failed to unmarshal state: %s (%w)", err, queue.CriticalErr) |
| 185 | } |
| 186 | |
| 187 | // Get fresh file to make sure task is not stale. |
| 188 | file, err := fm.Get(ctx, state.Uri, dbfs.WithFilePublicMetadata()) |
| 189 | if err != nil { |
| 190 | return task.StatusError, fmt.Errorf("failed to get latest file: %w", err) |
| 191 | } |
| 192 | |
| 193 | if file.PrimaryEntityID() != state.EntityID { |
| 194 | l.Debug("File %d entity changed, skipping copy index.", state.FileID) |
| 195 | return task.StatusCompleted, nil |
| 196 | } |
| 197 | |
| 198 | indexer := dep.SearchIndexer(ctx) |
| 199 | if err := indexer.CopyByFileID(ctx, state.OriginalFileID, state.FileID, state.OwnerID, state.EntityID); err != nil { |
| 200 | l.Warning("Failed to copy index from file %d to %d, falling back to full indexing: %s", state.OriginalFileID, state.FileID, err) |
| 201 | return performIndexing(ctx, fm, state.Uri, state.EntityID, state.FileID, state.OwnerID, file.Name(), false) |
| 202 | } |
| 203 | |
| 204 | // Patch metadata to mark file as indexed. |
| 205 | if err := fm.fs.PatchMetadata(ctx, []*fs.URI{state.Uri}, fs.MetadataPatch{ |
| 206 | Key: dbfs.FullTextIndexKey, |
| 207 | Value: hashid.EncodeEntityID(fm.hasher, state.EntityID), |
| 208 | }); err != nil { |
| 209 | return task.StatusError, fmt.Errorf("failed to patch metadata: %w", err) |
| 210 | } |
| 211 | |
| 212 | l.Debug("Successfully copied index from file %d to %d.", state.OriginalFileID, state.FileID) |
| 213 | return task.StatusCompleted, nil |
| 214 | } |
| 215 | |
| 216 | type ( |
| 217 | FullTextChangeOwnerTask struct { |
nothing calls this directly
no test coverage detected