Administrative task for recalculating cached database counters #588

Closed
opened 2025-11-02 03:29:06 -06:00 by GiteaMirror · 4 comments
Owner

Originally created by @gerricom on GitHub (Mar 29, 2017).

  • Gitea version (or commit ref): 1.1
  • Git version: 2.7.4
  • Operating system: CentOS 6
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

The database holds a number of different cached counters e.g. num_comments in the issue table, or num_issues, num_closed_issues, ... in die repo table. If for any reason (migration failed, backup failed, ...) the original values are changed those num_-values won't change with them.

There should be an administrative task that recalculate all those values.

Originally created by @gerricom on GitHub (Mar 29, 2017). - Gitea version (or commit ref): 1.1 - Git version: 2.7.4 - Operating system: CentOS 6 - Database (use `[x]`): - [x] PostgreSQL - [x] MySQL - [x] MSSQL - [x] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] Not relevant - Log gist: ## Description The database holds a number of different cached counters e.g. `num_comments` in the issue table, or `num_issues`, `num_closed_issues`, ... in die repo table. If for any reason (migration failed, backup failed, ...) the original values are changed those num_-values won't change with them. There should be an administrative task that recalculate all those values.
Author
Owner

@strk commented on GitHub (Mar 29, 2017):

Would you be up to give this a try ?

@strk commented on GitHub (Mar 29, 2017): Would you be up to give this a try ?
Author
Owner

@gerricom commented on GitHub (Mar 29, 2017):

Unfortunately I'm not into go (this is my very first contact). I could provide raw (My)SQL-Queries to recalculate those values if this helps?

@gerricom commented on GitHub (Mar 29, 2017): Unfortunately I'm not into go (this is my very first contact). I could provide raw (My)SQL-Queries to recalculate those values if this helps?
Author
Owner

@strk commented on GitHub (Mar 29, 2017):

Diving into Go would help more, look at routers/admin/admin.go and models/repo.go
Looking at them myself I found a function that might be doing what you're after (update stats):
models.CheckRepoStats and there seems to be support for doing it periodically unless disabled by config:

        if setting.Cron.CheckRepoStats.Enabled {
                entry, err = c.AddFunc("Check repository statistics", setting.Cron.CheckRepoStats.Schedule, models.CheckRepoStats)
                if err != nil {
                        log.Fatal(4, "Cron[Check repository statistics]: %v", err)
                }
                if setting.Cron.CheckRepoStats.RunAtStart {
                        entry.Prev = time.Now()
                        entry.ExecTimes++
                        go models.CheckRepoStats()
                }
        }

Check out Cron in https://docs.gitea.io/en-us/config-cheat-sheet/

@strk commented on GitHub (Mar 29, 2017): Diving into Go would help more, look at `routers/admin/admin.go` and `models/repo.go` Looking at them myself I found a function that *might* be doing what you're after (update stats): `models.CheckRepoStats` and there seems to be support for doing it periodically unless disabled by config: ``` if setting.Cron.CheckRepoStats.Enabled { entry, err = c.AddFunc("Check repository statistics", setting.Cron.CheckRepoStats.Schedule, models.CheckRepoStats) if err != nil { log.Fatal(4, "Cron[Check repository statistics]: %v", err) } if setting.Cron.CheckRepoStats.RunAtStart { entry.Prev = time.Now() entry.ExecTimes++ go models.CheckRepoStats() } } ``` Check out `Cron` in https://docs.gitea.io/en-us/config-cheat-sheet/
Author
Owner

@stale[bot] commented on GitHub (Feb 16, 2019):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

@stale[bot] commented on GitHub (Feb 16, 2019): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#588