mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-11-04 00:11:04 +00:00 
			
		
		
		
	This PR replaces unnecessary calls to formatting functions (`fmt.Printf`, `fmt.Errorf`, ...) by non-formatting equivalents. Resolves #7967 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7994 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: chavacava <chavacava@noreply.codeberg.org> Co-committed-by: chavacava <chavacava@noreply.codeberg.org>
		
			
				
	
	
		
			49 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
// Copyright 2020 The Gitea Authors. All rights reserved.
 | 
						|
// SPDX-License-Identifier: MIT
 | 
						|
 | 
						|
package stats
 | 
						|
 | 
						|
import (
 | 
						|
	"errors"
 | 
						|
 | 
						|
	repo_model "forgejo.org/models/repo"
 | 
						|
	"forgejo.org/modules/graceful"
 | 
						|
	"forgejo.org/modules/log"
 | 
						|
	"forgejo.org/modules/queue"
 | 
						|
	"forgejo.org/modules/setting"
 | 
						|
)
 | 
						|
 | 
						|
// statsQueue represents a queue to handle repository stats updates
 | 
						|
var statsQueue *queue.WorkerPoolQueue[int64]
 | 
						|
 | 
						|
// handle passed PR IDs and test the PRs
 | 
						|
func handler(items ...int64) []int64 {
 | 
						|
	for _, opts := range items {
 | 
						|
		if err := indexer.Index(opts); err != nil {
 | 
						|
			if !setting.IsInTesting {
 | 
						|
				log.Error("stats queue indexer.Index(%d) failed: %v", opts, err)
 | 
						|
			}
 | 
						|
		}
 | 
						|
	}
 | 
						|
	return nil
 | 
						|
}
 | 
						|
 | 
						|
func initStatsQueue() error {
 | 
						|
	statsQueue = queue.CreateUniqueQueue(graceful.GetManager().ShutdownContext(), "repo_stats_update", handler)
 | 
						|
	if statsQueue == nil {
 | 
						|
		return errors.New("unable to create repo_stats_update queue")
 | 
						|
	}
 | 
						|
	go graceful.GetManager().RunWithCancel(statsQueue)
 | 
						|
	return nil
 | 
						|
}
 | 
						|
 | 
						|
// UpdateRepoIndexer update a repository's entries in the indexer
 | 
						|
func UpdateRepoIndexer(repo *repo_model.Repository) error {
 | 
						|
	if err := statsQueue.Push(repo.ID); err != nil {
 | 
						|
		if err != queue.ErrAlreadyInQueue {
 | 
						|
			return err
 | 
						|
		}
 | 
						|
		log.Debug("Repo ID: %d already queued", repo.ID)
 | 
						|
	}
 | 
						|
	return nil
 | 
						|
}
 |