StartReindex triggers a full reindex of all data from the database to Typesense. The reindex runs asynchronously to avoid HTTP timeouts. Parameters: - c: The Gin context containing the request and response. Responses: - 202 Accepted: Reindex started successfully, returns initial progress. - 409 Co
(c *gin.Context)
| 47 | // - 202 Accepted: Reindex started successfully, returns initial progress. |
| 48 | // - 409 Conflict: If a reindex is already in progress. |
| 49 | func (a Api) StartReindex(c *gin.Context) { |
| 50 | var req ReindexRequest |
| 51 | if err := c.ShouldBindJSON(&req); err != nil { |
| 52 | req.BatchSize = 0 |
| 53 | } |
| 54 | |
| 55 | if req.BatchSize <= 0 { |
| 56 | req.BatchSize = 1000 |
| 57 | } |
| 58 | |
| 59 | globalReindexManager.mu.Lock() |
| 60 | if globalReindexManager.service != nil { |
| 61 | progress := globalReindexManager.service.GetProgress() |
| 62 | if progress.Status == "in_progress" { |
| 63 | globalReindexManager.mu.Unlock() |
| 64 | c.JSON(http.StatusConflict, gin.H{ |
| 65 | "error": "A reindex operation is already in progress", |
| 66 | "progress": progress, |
| 67 | }) |
| 68 | return |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | config := search.ReindexConfig{ |
| 73 | BatchSize: req.BatchSize, |
| 74 | } |
| 75 | |
| 76 | reindexService := search.NewReindexService( |
| 77 | a.ledgerforge.GetSearchClient(), |
| 78 | a.ledgerforge.GetDataSource(), |
| 79 | config, |
| 80 | ) |
| 81 | globalReindexManager.service = reindexService |
| 82 | globalReindexManager.mu.Unlock() |
| 83 | |
| 84 | go func() { |
| 85 | _, _ = reindexService.StartReindex(context.Background()) |
| 86 | }() |
| 87 | |
| 88 | c.JSON(http.StatusAccepted, gin.H{ |
| 89 | "message": "Reindex operation started", |
| 90 | "progress": reindexService.GetProgress(), |
| 91 | }) |
| 92 | } |
| 93 | |
| 94 | // GetReindexProgress returns the current progress of the reindex operation. |
| 95 | // |
nothing calls this directly
no test coverage detected