mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
return of the stats page
This commit is contained in:
parent
b54704fba5
commit
ef21b7c7d0
4 changed files with 54 additions and 27 deletions
|
@ -82,7 +82,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "Statistics",
|
"title": "Statistics",
|
||||||
"url": "/stats"
|
"url": "/pages/stats"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "About",
|
"title": "About",
|
||||||
|
|
|
@ -26,6 +26,7 @@ defmodule Philomena.Application do
|
||||||
|
|
||||||
# Start the endpoint when the application starts
|
# Start the endpoint when the application starts
|
||||||
PhilomenaWeb.Endpoint,
|
PhilomenaWeb.Endpoint,
|
||||||
|
PhilomenaWeb.StatsUpdater,
|
||||||
|
|
||||||
# Connection drainer for SIGTERM
|
# Connection drainer for SIGTERM
|
||||||
{RanchConnectionDrainer, ranch_ref: PhilomenaWeb.Endpoint.HTTP, shutdown: 30_000}
|
{RanchConnectionDrainer, ranch_ref: PhilomenaWeb.Endpoint.HTTP, shutdown: 30_000}
|
||||||
|
|
|
@ -499,7 +499,6 @@ defmodule PhilomenaWeb.Router do
|
||||||
|
|
||||||
resources "/dnp", DnpEntryController, only: [:index, :show]
|
resources "/dnp", DnpEntryController, only: [:index, :show]
|
||||||
resources "/staff", StaffController, only: [:index]
|
resources "/staff", StaffController, only: [:index]
|
||||||
resources "/stats", StatController, only: [:index]
|
|
||||||
resources "/channels", ChannelController, only: [:index, :show]
|
resources "/channels", ChannelController, only: [:index, :show]
|
||||||
resources "/settings", SettingController, only: [:edit, :update], singleton: true
|
resources "/settings", SettingController, only: [:edit, :update], singleton: true
|
||||||
resources "/duplicate_reports", DuplicateReportController, only: [:index, :show, :create]
|
resources "/duplicate_reports", DuplicateReportController, only: [:index, :show, :create]
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
defmodule PhilomenaWeb.StatController do
|
defmodule PhilomenaWeb.StatsUpdater do
|
||||||
use PhilomenaWeb, :controller
|
|
||||||
|
|
||||||
alias Philomena.Elasticsearch
|
alias Philomena.Elasticsearch
|
||||||
alias Philomena.Servers.Config
|
alias Philomena.Servers.Config
|
||||||
alias Philomena.Images.Image
|
alias Philomena.Images.Image
|
||||||
|
@ -14,10 +12,24 @@ defmodule PhilomenaWeb.StatController do
|
||||||
alias Philomena.Commissions.Commission
|
alias Philomena.Commissions.Commission
|
||||||
alias Philomena.Commissions.Item
|
alias Philomena.Commissions.Item
|
||||||
alias Philomena.Reports.Report
|
alias Philomena.Reports.Report
|
||||||
|
alias Philomena.StaticPages.StaticPage
|
||||||
alias Philomena.Repo
|
alias Philomena.Repo
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
def index(conn, _params) do
|
def child_spec([]) do
|
||||||
|
%{
|
||||||
|
id: PhilomenaWeb.StatsUpdater,
|
||||||
|
start: {PhilomenaWeb.StatsUpdater, :start_link, [[]]}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def start_link([]) do
|
||||||
|
{:ok, spawn_link(&run/0)}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp run do
|
||||||
|
:timer.sleep(:timer.seconds(300))
|
||||||
|
|
||||||
{gallery_count, gallery_size, distinct_creators, images_in_galleries} = galleries()
|
{gallery_count, gallery_size, distinct_creators, images_in_galleries} = galleries()
|
||||||
{open_reports, report_count, response_time} = moderation()
|
{open_reports, report_count, response_time} = moderation()
|
||||||
{open_commissions, commission_items} = commissions()
|
{open_commissions, commission_items} = commissions()
|
||||||
|
@ -25,8 +37,9 @@ defmodule PhilomenaWeb.StatController do
|
||||||
{forums, topics, posts} = forums()
|
{forums, topics, posts} = forums()
|
||||||
{users, users_24h} = users()
|
{users, users_24h} = users()
|
||||||
|
|
||||||
render(
|
result =
|
||||||
conn,
|
Phoenix.View.render(
|
||||||
|
PhilomenaWeb.StatView,
|
||||||
"index.html",
|
"index.html",
|
||||||
image_aggs: image_aggs,
|
image_aggs: image_aggs,
|
||||||
comment_aggs: comment_aggs,
|
comment_aggs: comment_aggs,
|
||||||
|
@ -43,9 +56,23 @@ defmodule PhilomenaWeb.StatController do
|
||||||
gallery_count: gallery_count,
|
gallery_count: gallery_count,
|
||||||
gallery_size: gallery_size,
|
gallery_size: gallery_size,
|
||||||
distinct_creators: distinct_creators,
|
distinct_creators: distinct_creators,
|
||||||
images_in_galleries: images_in_galleries,
|
images_in_galleries: images_in_galleries
|
||||||
title: "Statistics"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
|
||||||
|
|
||||||
|
static_page =
|
||||||
|
%{
|
||||||
|
title: "Statistics",
|
||||||
|
slug: "stats",
|
||||||
|
body: Phoenix.HTML.safe_to_string(result),
|
||||||
|
created_at: now,
|
||||||
|
updated_at: now
|
||||||
|
}
|
||||||
|
|
||||||
|
Repo.insert_all(StaticPage, [static_page], on_conflict: {:replace, [:body, :updated_at]}, conflict_target: :slug)
|
||||||
|
|
||||||
|
run()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp aggregations do
|
defp aggregations do
|
Loading…
Reference in a new issue