From 82d1a0d1fa38bd1360ff6065e83a0c8cf69ca62a Mon Sep 17 00:00:00 2001 From: Miha Lunar Date: Mon, 9 Sep 2024 00:02:16 +0200 Subject: [PATCH] Fix rescan file counting --- main.go | 27 ++++++++++++------------ ui/src/components/CollectionSettings.vue | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 69c7644..f9c16b4 100644 --- a/main.go +++ b/main.go @@ -282,8 +282,8 @@ func getCollectionById(id string) *collection.Collection { return nil } -func newFileIndexTask(collection *collection.Collection) Task { - return Task{ +func newFileIndexTask(collection *collection.Collection) *Task { + return &Task{ Type: string(openapi.TaskTypeINDEXFILES), Id: fmt.Sprintf("index-files-%v", collection.Id), Name: fmt.Sprintf("Indexing files %v", collection.Name), @@ -547,9 +547,9 @@ func (*Api) GetTasks(w http.ResponseWriter, r *http.Request, params openapi.GetT return } - tasks := make([]Task, 0) + tasks := make([]*Task, 0) globalTasks.Range(func(key, value interface{}) bool { - t := value.(Task) + t := value.(*Task) add := true if params.Type != nil && t.Type != string(*params.Type) { @@ -572,6 +572,7 @@ func (*Api) GetTasks(w http.ResponseWriter, r *http.Request, params openapi.GetT add = false } } + if add { tasks = append(tasks, t) } @@ -585,7 +586,7 @@ func (*Api) GetTasks(w http.ResponseWriter, r *http.Request, params openapi.GetT }) respond(w, r, http.StatusOK, struct { - Items []Task `json:"items"` + Items []*Task `json:"items"` }{ Items: tasks, }) @@ -619,7 +620,7 @@ func (*Api) PostTasks(w http.ResponseWriter, r *http.Request) { Metadata: true, }) stored, _ := globalTasks.Load("index-metadata") - task := stored.(Task) + task := stored.(*Task) respond(w, r, http.StatusAccepted, task) case openapi.TaskTypeINDEXCONTENTS: @@ -628,7 +629,7 @@ func (*Api) PostTasks(w http.ResponseWriter, r *http.Request) { Embedding: true, }) stored, _ := globalTasks.Load("index-contents") - task := stored.(Task) + task := stored.(*Task) respond(w, r, http.StatusAccepted, task) case openapi.TaskTypeINDEXCONTENTSCOLOR: @@ -636,7 +637,7 @@ func (*Api) PostTasks(w http.ResponseWriter, r *http.Request) { Color: true, }) stored, _ := globalTasks.Load("index-contents") - task := stored.(Task) + task := stored.(*Task) respond(w, r, http.StatusAccepted, task) case openapi.TaskTypeINDEXCONTENTSAI: @@ -644,7 +645,7 @@ func (*Api) PostTasks(w http.ResponseWriter, r *http.Request) { Embedding: true, }) stored, _ := globalTasks.Load("index-contents") - task := stored.(Task) + task := stored.(*Task) respond(w, r, http.StatusAccepted, task) default: @@ -1110,10 +1111,10 @@ type TileRequestConfig struct { LogStats bool `json:"log_stats"` } -func indexCollection(collection *collection.Collection) (task Task, existing bool) { +func indexCollection(collection *collection.Collection) (task *Task, existing bool) { task = newFileIndexTask(collection) stored, existing := globalTasks.LoadOrStore(task.Id, task) - task = stored.(Task) + task = stored.(*Task) if existing { return } @@ -1457,7 +1458,7 @@ func main() { return } - metadataTask := Task{ + metadataTask := &Task{ Type: string(openapi.TaskTypeINDEXMETADATA), Id: "index-metadata", Name: "Indexing metadata", @@ -1465,7 +1466,7 @@ func main() { } globalTasks.Store(metadataTask.Id, metadataTask) - contentsTask := Task{ + contentsTask := &Task{ Type: string(openapi.TaskTypeINDEXCONTENTS), Id: "index-contents", Name: "Indexing contents", diff --git a/ui/src/components/CollectionSettings.vue b/ui/src/components/CollectionSettings.vue index bb0f9c1..060a156 100644 --- a/ui/src/components/CollectionSettings.vue +++ b/ui/src/components/CollectionSettings.vue @@ -39,7 +39,7 @@ const { const fileCount = computed(() => { if (collection.value) { for (const task of tasks.value) { - if (task.type != "INDEX") continue; + if (task.type != "INDEX_FILES") continue; if (task.collection_id != collection.value.id) continue; return task.done.toLocaleString(); }