adjust json response, minor clean up

This commit is contained in:
Cyberes 2024-03-23 17:38:02 -06:00
parent fdd7f08b12
commit 933670c63a
7 changed files with 15 additions and 27 deletions

View File

@ -152,7 +152,7 @@ func APISearch(w http.ResponseWriter, r *http.Request) {
}
searchDuration := time.Since(searchStart) // .Round(time.Second)
log.Debugf(`ROUTES:Search - %s - Query: "%s" - Results: %d - Elapsed: %d`, logging.GetRealIP(r), queryString, len(results), searchDuration)
log.Debugf(`ROUTES:Search - %s - Query: "%s" - Results: %d - Elapsed: %s`, logging.GetRealIP(r), queryString, len(results), searchDuration)
response := map[string]interface{}{
"results": results,

View File

@ -37,19 +37,20 @@ func APIAdminCrawlsInfo(w http.ResponseWriter, r *http.Request) {
}
var elasticWorkers map[string]interface{}
var elasticQueueSize int
if (refreshSyncRunning || fullSyncRunning) && globals.ElasticCrawlers != nil {
// If no sync is running then these vars will not exist.
elasticWorkers = map[string]interface{}{
"busy": globals.ElasticCrawlers.BusyWorkers,
"alive": config.GetConfig().ElasticsearchSyncWorkers,
"queueSize": globals.ElasticCrawlers.Queue.GetQueuedJobs(),
}
elasticQueueSize = globals.ElasticCrawlers.Queue.GetQueuedJobs()
} else {
elasticWorkers = map[string]interface{}{
"busy": 0,
"alive": 0,
"queueSize": 0,
}
elasticQueueSize = 0
}
response := map[string]interface{}{
@ -67,6 +68,7 @@ func APIAdminCrawlsInfo(w http.ResponseWriter, r *http.Request) {
},
"elastic": map[string]interface{}{
"workers": elasticWorkers,
"queueSize": elasticQueueSize,
"syncRunning": map[string]interface{}{
"refresh": refreshSyncRunning,
"full": fullSyncRunning,

View File

@ -116,7 +116,6 @@ func main() {
// Start the Elastic connection, so it can initialize while we're doing the initial crawl.
// If we fail to establish a connection to Elastic, don't kill the entire server. Instead, just disable Elastic.
if cfg.ElasticsearchEnable && !cliArgs.disableElasticSync {
fmt.Println(config.GetConfig().ElasticsearchSyncWorkers + 1)
esCfg := elasticsearch.Config{
Addresses: []string{
cfg.ElasticsearchEndpoint,

View File

@ -16,6 +16,7 @@ import (
"sync"
)
// TODO: is there a better way to store this data? It appears to eat up a lot of memory.
// existingKeys is a global variable called by the Walker callback: addToElasticsearch().
// It is set only by syncElasticsearch() when a sync is started. Only one sync can run at a time.
// A global is needed since there is no way to pass variables like this to the workers.

View File

@ -10,14 +10,6 @@ import (
"time"
)
func getElasticSize() (int, error) {
keysByPath, _, err := getPathsFromIndex(true, 100)
if err != nil {
return -1, err
}
return len(keysByPath), nil
}
func getPathsFromIndex(doScroll bool, withSize int) (map[string]string, map[string]string, error) {
// This may take a bit if the index is very large, so avoid calling this.

View File

@ -33,23 +33,17 @@ func GetRealIP(r *http.Request) string {
// Or just use the header the user specified.
forwarded = r.Header.Get(config.GetConfig().HTTPRealIPHeader)
}
return ip
}
func LogRequest(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
sw := statusWriter{ResponseWriter: w, status: http.StatusOK} // set default status
start := time.Now() // record the start time
start := time.Now()
handler.ServeHTTP(&sw, r)
end := time.Now() // record the end time
// calculate the duration
end := time.Now()
duration := end.Sub(start)
ip := GetRealIP(r)
log.Infof("HTTP - %s %d %s from %s took %v", r.Method, sw.status, r.URL.RequestURI(), ip, duration)
})
}

View File

@ -45,12 +45,12 @@ func NewResponseItem(cacheItem *cacheitem.Item) *ResponseItem {
IsDir: cacheItem.IsDir,
IsSymlink: cacheItem.IsSymlink,
Cached: cacheItem.Cached,
Children: make([]*ResponseItem, len(cacheItem.Children)),
Children: make([]*ResponseItem, len(cacheItem.Children)), // avoid a null entry for the children key in the JSON.
MimeType: cacheItem.MimeType,
}
// Grab the children from the cache and add them to newResponseItem.
if len(cacheItem.Children) > 0 { // avoid a null entry for the children key in the JSON.
if len(cacheItem.Children) > 0 {
var children []*ResponseItem
for _, child := range cacheItem.Children {
childItem, found := sharedcache.Cache.Get(child)