Files
OpenList/internal/search/meilisearch/utils.go
ImoutoHeaven 316d4caf37 feat(search): Add task queue for Meilisearch to prevent race conditions (#1423)
* Add task queue for Meilisearch to prevent race conditions

- Implement TaskQueueManager for async index operations
- Queue update tasks and process them in batches every 30 seconds
- Check pending task status before executing new operations
- Optimize batch indexing and deletion logic
- Fix type assertion bug in buildSearchDocumentFromResults

* fix(search): re-enqueue skipped tasks to prevent task loss

When tasks are skipped due to pending dependencies, they are now
re-enqueued if not already in queue. This prevents task loss while
avoiding overwriting newer snapshots for the same parent.

* fix(copilot-comment): Invoke Stop() & err of SliceConvert

---------

Co-authored-by: ImoutoHeaven <noreply@imoutoheaven.org>
Co-authored-by: jyxjjj <773933146@qq.com>
2025-11-25 11:38:27 +08:00

31 lines
977 B
Go

package meilisearch
import (
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
)
// hashPath hashes a path with SHA-1.
// Path-relative exact matching should use hash,
// because filtering strings on meilisearch is case-insensitive.
func hashPath(path string) string {
return utils.HashData(utils.SHA1, []byte(path))
}
func buildSearchDocumentFromResults(results map[string]any) *searchDocument {
document := &searchDocument{}
// use assertion test to avoid panic
document.SearchNode.Parent, _ = results["parent"].(string)
document.SearchNode.Name, _ = results["name"].(string)
document.SearchNode.IsDir, _ = results["is_dir"].(bool)
// JSON numbers are typically float64, not int64
if size, ok := results["size"].(float64); ok {
document.SearchNode.Size = int64(size)
}
document.ID, _ = results["id"].(string)
document.ParentHash, _ = results["parent_hash"].(string)
document.ParentPathHashes, _ = results["parent_path_hashes"].([]string)
return document
}