Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rescan file counting #118

Merged
merged 1 commit into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading