mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-19 11:36:47 +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"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (db *DB) CountHistoryEntries(ctx context.Context) (int64, error) {
|
func (db *DB) CountApproximateHistoryEntries(ctx context.Context) (int64, error) {
|
||||||
var numDbEntries int64
|
var numDbEntries int64
|
||||||
tx := db.WithContext(ctx).Model(&shared.EncHistoryEntry{}).Count(&numDbEntries)
|
err := db.WithContext(ctx).Raw("SELECT reltuples::bigint FROM pg_class WHERE relname = 'enc_history_entries'").Row().Scan(&numDbEntries)
|
||||||
if tx.Error != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("tx.Error: %w", tx.Error)
|
return 0, fmt.Errorf("DB Error: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return numDbEntries, nil
|
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) {
|
func (s *Server) healthCheckHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if s.isProductionEnvironment {
|
if s.isProductionEnvironment {
|
||||||
encHistoryEntryCount, err := s.db.CountHistoryEntries(r.Context())
|
encHistoryEntryCount, err := s.db.CountApproximateHistoryEntries(r.Context())
|
||||||
checkGormError(err)
|
checkGormError(err)
|
||||||
if encHistoryEntryCount < 1000 {
|
if encHistoryEntryCount < 1000 {
|
||||||
panic("Suspiciously few enc history entries!")
|
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())
|
numEntriesProcessed, err := s.db.UsageDataTotal(r.Context())
|
||||||
checkGormError(err)
|
checkGormError(err)
|
||||||
|
|
||||||
numDbEntries, err := s.db.CountHistoryEntries(r.Context())
|
numDbEntries, err := s.db.CountApproximateHistoryEntries(r.Context())
|
||||||
checkGormError(err)
|
checkGormError(err)
|
||||||
|
|
||||||
oneWeek := time.Hour * 24 * 7
|
oneWeek := time.Hour * 24 * 7
|
||||||
|
Loading…
x
Reference in New Issue
Block a user