mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-18 19:16:44 +02:00
Swap healthcheck endpoint to count the approximate number of history entries
This commit is contained in:
parent
63741a0d14
commit
6e33e1ee1d
@ -8,11 +8,11 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (db *DB) CountHistoryEntries(ctx context.Context) (int64, error) {
|
||||
func (db *DB) CountApproximateHistoryEntries(ctx context.Context) (int64, error) {
|
||||
var numDbEntries int64
|
||||
tx := db.WithContext(ctx).Model(&shared.EncHistoryEntry{}).Count(&numDbEntries)
|
||||
if tx.Error != nil {
|
||||
return 0, fmt.Errorf("tx.Error: %w", tx.Error)
|
||||
err := db.WithContext(ctx).Raw("SELECT reltuples::bigint FROM pg_class WHERE relname = 'enc_history_entries'").Row().Scan(&numDbEntries)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("DB Error: %w", err)
|
||||
}
|
||||
|
||||
return numDbEntries, nil
|
||||
|
@ -222,7 +222,7 @@ func (s *Server) feedbackHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (s *Server) healthCheckHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if s.isProductionEnvironment {
|
||||
encHistoryEntryCount, err := s.db.CountHistoryEntries(r.Context())
|
||||
encHistoryEntryCount, err := s.db.CountApproximateHistoryEntries(r.Context())
|
||||
checkGormError(err)
|
||||
if encHistoryEntryCount < 1000 {
|
||||
panic("Suspiciously few enc history entries!")
|
||||
@ -285,7 +285,7 @@ func (s *Server) statsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
numEntriesProcessed, err := s.db.UsageDataTotal(r.Context())
|
||||
checkGormError(err)
|
||||
|
||||
numDbEntries, err := s.db.CountHistoryEntries(r.Context())
|
||||
numDbEntries, err := s.db.CountApproximateHistoryEntries(r.Context())
|
||||
checkGormError(err)
|
||||
|
||||
oneWeek := time.Hour * 24 * 7
|
||||
|
Loading…
x
Reference in New Issue
Block a user