mirror of
https://github.com/knadh/listmonk.git
synced 2024-11-15 03:55:06 +08:00
5a3664aee2
- Add materialized views for list -> subscriber counts, dashboard chart, and dashboard aggregate stats that slow down significantly on large databases (with millions or tens of millions of subscribers). These slow queries involve full table scan COUNTS(). - Add a toggle to enable caching slow results in Settings -> Performance. - Add support for setting a cron string that crons and periodically refreshes aggregated stats in materialized views. Closes #1019.
34 lines
1,006 B
Go
34 lines
1,006 B
Go
package core
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/jmoiron/sqlx/types"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
// GetDashboardCharts returns chart data points to render on the dashboard.
|
|
func (c *Core) GetDashboardCharts() (types.JSONText, error) {
|
|
_ = c.refreshCache(matDashboardCharts, false)
|
|
|
|
var out types.JSONText
|
|
if err := c.q.GetDashboardCharts.Get(&out); err != nil {
|
|
return nil, echo.NewHTTPError(http.StatusInternalServerError,
|
|
c.i18n.Ts("globals.messages.errorFetching", "name", "dashboard charts", "error", pqErrMsg(err)))
|
|
}
|
|
|
|
return out, nil
|
|
}
|
|
|
|
// GetDashboardCounts returns stats counts to show on the dashboard.
|
|
func (c *Core) GetDashboardCounts() (types.JSONText, error) {
|
|
_ = c.refreshCache(matDashboardCounts, false)
|
|
|
|
var out types.JSONText
|
|
if err := c.q.GetDashboardCounts.Get(&out); err != nil {
|
|
return nil, echo.NewHTTPError(http.StatusInternalServerError,
|
|
c.i18n.Ts("globals.messages.errorFetching", "name", "dashboard stats", "error", pqErrMsg(err)))
|
|
}
|
|
|
|
return out, nil
|
|
}
|