MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / StartReindex

Method StartReindex

api/reindex.go:49–92  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

47// - 202 Accepted: Reindex started successfully, returns initial progress.
48// - 409 Conflict: If a reindex is already in progress.
49func (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//

Callers

nothing calls this directly

Calls 7

GetProgressMethod · 0.95
StartReindexMethod · 0.95
NewReindexServiceFunction · 0.92
GetSearchClientMethod · 0.80
GetDataSourceMethod · 0.80
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected