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

View File

@ -7,19 +7,12 @@ import (
"github.com/elastic/go-elasticsearch/v8/esapi" "github.com/elastic/go-elasticsearch/v8/esapi"
) )
func startRemoveStaleItemsFromElasticsearch() { func startRemoveStaleItemsFromElasticsearch(pathsByKey map[string]string) {
// Retrieve all keys from Elasticsearch
pathsByKey, _, err := getPathsFromIndex()
if err != nil {
log.Errorf("ELASTIC - Error retrieving keys from Elasticsearch: %s", err)
return
}
log.Debugln("ELASTIC - Checking for removed items...") 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 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 { for key, path := range pathsByKey {
go Queue.AddJob(DeleteJob{Key: key, Path: path}) Queue.AddJob(DeleteJob{Key: key, Path: path})
} }
} }