reorder some logic

This commit is contained in:
Cyberes 2023-12-13 22:51:13 -07:00
parent 0ee56f20e7
commit 39513ffc36
2 changed files with 5 additions and 12 deletions

View File

@ -61,8 +61,6 @@ func syncElasticsearch(doFullSync bool) {
log.Infof("ELASTIC - started a %s sync.", syncType)
start := time.Now()
startRemoveStaleItemsFromElasticsearch()
// Set global variables for the workers to read.
fullSync = doFullSync
var err error
@ -72,6 +70,8 @@ func syncElasticsearch(doFullSync bool) {
return
}
startRemoveStaleItemsFromElasticsearch(globalPathsByKey)
dc := DirectoryCrawler.NewDirectoryCrawler()
err = dc.Crawl(config.GetConfig().RootDir, addToElasticsearch)
if err != nil {
@ -90,8 +90,8 @@ func logElasticConnError(err error) {
log.Errorf("ELASTIC - Failed to read the index: %s", err)
}
// EnableElasticsearchConnection tests the connection to Elastic and enables the backend if it's successful.
func EnableElasticsearchConnection() {
// Test connection to Elastic.
esSize, err := getElasticSize()
if err != nil {
logElasticConnError(err)

View File

@ -7,19 +7,12 @@ import (
"github.com/elastic/go-elasticsearch/v8/esapi"
)
func startRemoveStaleItemsFromElasticsearch() {
// Retrieve all keys from Elasticsearch
pathsByKey, _, err := getPathsFromIndex()
if err != nil {
log.Errorf("ELASTIC - Error retrieving keys from Elasticsearch: %s", err)
return
}
func startRemoveStaleItemsFromElasticsearch(pathsByKey map[string]string) {
log.Debugln("ELASTIC - Checking for removed items...")
// For each key in Elasticsearch, create a job to check (and remove it if the key no longer exists in the cache).
for key, path := range pathsByKey {
go Queue.AddJob(DeleteJob{Key: key, Path: path})
Queue.AddJob(DeleteJob{Key: key, Path: path})
}
}