Skip to content

Commit

Permalink
Fix rescan file counting (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
SmilyOrg authored Sep 8, 2024
2 parents 637fe90 + 82d1a0d commit 4f4f5c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
27 changes: 14 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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) {
Expand All @@ -572,6 +572,7 @@ func (*Api) GetTasks(w http.ResponseWriter, r *http.Request, params openapi.GetT
add = false
}
}

if add {
tasks = append(tasks, t)
}
Expand All @@ -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,
})
Expand Down Expand Up @@ -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:
Expand All @@ -628,23 +629,23 @@ 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:
imageSource.IndexContents(collection.Dirs, collection.IndexLimit, image.Missing{
Color: true,
})
stored, _ := globalTasks.Load("index-contents")
task := stored.(Task)
task := stored.(*Task)
respond(w, r, http.StatusAccepted, task)

case openapi.TaskTypeINDEXCONTENTSAI:
imageSource.IndexContents(collection.Dirs, collection.IndexLimit, image.Missing{
Embedding: true,
})
stored, _ := globalTasks.Load("index-contents")
task := stored.(Task)
task := stored.(*Task)
respond(w, r, http.StatusAccepted, task)

default:
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -1457,15 +1458,15 @@ func main() {
return
}

metadataTask := Task{
metadataTask := &Task{
Type: string(openapi.TaskTypeINDEXMETADATA),
Id: "index-metadata",
Name: "Indexing metadata",
Queue: "index_metadata",
}
globalTasks.Store(metadataTask.Id, metadataTask)

contentsTask := Task{
contentsTask := &Task{
Type: string(openapi.TaskTypeINDEXCONTENTS),
Id: "index-contents",
Name: "Indexing contents",
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/CollectionSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 4f4f5c4

Please sign in to comment.