diff --git a/.env.example b/.env.example
index b6566ff..ad1d1e6 100644
--- a/.env.example
+++ b/.env.example
@@ -15,7 +15,7 @@ BASE_URL=http://localhost:5173
# S3/MinIO configuration, required for avatars, pride flags, and data exports
# Note: MINIO_ENDPOINT must be set and look like a minio endpoint, but doesn't
-# have to actually point to one you have access to
+# have to actually point to anything real
MINIO_ENDPOINT=example.com
MINIO_BUCKET=
MINIO_ACCESS_KEY_ID=
@@ -40,5 +40,5 @@ TUMBLR_CLIENT_ID=
TUMBLR_CLIENT_SECRET=
# Discord bot config - provide the app's public key in addition to client ID/
-# secret from above to let the bot to respond to command interactions over HTTP
+# secret above to let the bot respond to command interactions over HTTP
DISCORD_PUBLIC_KEY=
diff --git a/backend/db/db.go b/backend/db/db.go
index 5f7af5a..13e12f2 100644
--- a/backend/db/db.go
+++ b/backend/db/db.go
@@ -6,6 +6,7 @@ import (
"fmt"
"net/url"
"os"
+ "sync"
"codeberg.org/pronounscc/pronouns.cc/backend/log"
"emperror.dev/errors"
@@ -41,6 +42,10 @@ type DB struct {
baseURL *url.URL
TotalRequests prometheus.Counter
+
+ activeUsersDay, activeUsersWeek, activeUsersMonth int64
+ usersTotal, membersTotal int64
+ countMu sync.RWMutex
}
func New() (*DB, error) {
diff --git a/backend/db/fediverse.go b/backend/db/fediverse.go
index d319cad..eeadd79 100644
--- a/backend/db/fediverse.go
+++ b/backend/db/fediverse.go
@@ -48,7 +48,7 @@ func (f FediverseApp) ClientConfig() *oauth2.Config {
}
func (f FediverseApp) MastodonCompatible() bool {
- return f.InstanceType == "mastodon" || f.InstanceType == "pleroma" || f.InstanceType == "akkoma" || f.InstanceType == "pixelfed"
+ return f.InstanceType == "mastodon" || f.InstanceType == "pleroma" || f.InstanceType == "akkoma" || f.InstanceType == "pixelfed" || f.InstanceType == "gotosocial"
}
func (f FediverseApp) Misskey() bool {
diff --git a/backend/db/metrics.go b/backend/db/metrics.go
index c2a4cf9..96661dd 100644
--- a/backend/db/metrics.go
+++ b/backend/db/metrics.go
@@ -21,6 +21,11 @@ func (db *DB) initMetrics() (err error) {
if err != nil {
log.Errorf("getting user count for metrics: %v", err)
}
+
+ db.countMu.Lock()
+ db.usersTotal = count
+ db.countMu.Unlock()
+
return float64(count)
}))
if err != nil {
@@ -35,6 +40,11 @@ func (db *DB) initMetrics() (err error) {
if err != nil {
log.Errorf("getting member count for metrics: %v", err)
}
+
+ db.countMu.Lock()
+ db.membersTotal = count
+ db.countMu.Unlock()
+
return float64(count)
}))
if err != nil {
@@ -49,6 +59,11 @@ func (db *DB) initMetrics() (err error) {
if err != nil {
log.Errorf("getting active user count for metrics: %v", err)
}
+
+ db.countMu.Lock()
+ db.activeUsersMonth = count
+ db.countMu.Unlock()
+
return float64(count)
}))
if err != nil {
@@ -63,6 +78,11 @@ func (db *DB) initMetrics() (err error) {
if err != nil {
log.Errorf("getting active user count for metrics: %v", err)
}
+
+ db.countMu.Lock()
+ db.activeUsersWeek = count
+ db.countMu.Unlock()
+
return float64(count)
}))
if err != nil {
@@ -77,6 +97,11 @@ func (db *DB) initMetrics() (err error) {
if err != nil {
log.Errorf("getting active user count for metrics: %v", err)
}
+
+ db.countMu.Lock()
+ db.activeUsersDay = count
+ db.countMu.Unlock()
+
return float64(count)
}))
if err != nil {
@@ -107,6 +132,22 @@ func (db *DB) initMetrics() (err error) {
return nil
}
+func (db *DB) Counts(ctx context.Context) (numUsers, numMembers, usersDay, usersWeek, usersMonth int64) {
+ db.countMu.Lock()
+ if db.usersTotal != 0 {
+ defer db.countMu.Unlock()
+ return db.usersTotal, db.membersTotal, db.activeUsersDay, db.activeUsersWeek, db.activeUsersMonth
+ }
+ db.countMu.Unlock()
+
+ numUsers, _ = db.TotalUserCount(ctx)
+ numMembers, _ = db.TotalMemberCount(ctx)
+ usersDay, _ = db.ActiveUsers(ctx, ActiveDay)
+ usersWeek, _ = db.ActiveUsers(ctx, ActiveWeek)
+ usersMonth, _ = db.ActiveUsers(ctx, ActiveMonth)
+ return numUsers, numMembers, usersDay, usersWeek, usersMonth
+}
+
func (db *DB) TotalUserCount(ctx context.Context) (numUsers int64, err error) {
err = db.QueryRow(ctx, "SELECT COUNT(*) FROM users WHERE deleted_at IS NULL").Scan(&numUsers)
if err != nil {
diff --git a/backend/routes/auth/fediverse.go b/backend/routes/auth/fediverse.go
index 0f0511c..b3f2f62 100644
--- a/backend/routes/auth/fediverse.go
+++ b/backend/routes/auth/fediverse.go
@@ -67,7 +67,7 @@ func (s *Server) noAppFediverseURL(ctx context.Context, w http.ResponseWriter, r
switch softwareName {
case "misskey", "foundkey", "calckey":
return s.noAppMisskeyURL(ctx, w, r, softwareName, instance)
- case "mastodon", "pleroma", "akkoma", "pixelfed":
+ case "mastodon", "pleroma", "akkoma", "pixelfed", "gotosocial":
case "glitchcafe":
// plural.cafe (potentially other instances too?) runs Mastodon but changes the software name
// changing it back to mastodon here for consistency
diff --git a/backend/routes/meta/meta.go b/backend/routes/meta/meta.go
index da59f8d..ebae428 100644
--- a/backend/routes/meta/meta.go
+++ b/backend/routes/meta/meta.go
@@ -4,9 +4,7 @@ import (
"net/http"
"os"
- "codeberg.org/pronounscc/pronouns.cc/backend/db"
"codeberg.org/pronounscc/pronouns.cc/backend/server"
- "emperror.dev/errors"
"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
)
@@ -39,30 +37,7 @@ type MetaUsers struct {
func (s *Server) meta(w http.ResponseWriter, r *http.Request) error {
ctx := r.Context()
- numUsers, err := s.DB.TotalUserCount(ctx)
- if err != nil {
- return errors.Wrap(err, "querying user count")
- }
-
- activeMonth, err := s.DB.ActiveUsers(ctx, db.ActiveMonth)
- if err != nil {
- return errors.Wrap(err, "querying user count")
- }
-
- activeWeek, err := s.DB.ActiveUsers(ctx, db.ActiveWeek)
- if err != nil {
- return errors.Wrap(err, "querying user count")
- }
-
- activeDay, err := s.DB.ActiveUsers(ctx, db.ActiveDay)
- if err != nil {
- return errors.Wrap(err, "querying user count")
- }
-
- numMembers, err := s.DB.TotalMemberCount(ctx)
- if err != nil {
- return errors.Wrap(err, "querying user count")
- }
+ numUsers, numMembers, activeDay, activeWeek, activeMonth := s.DB.Counts(ctx)
render.JSON(w, r, MetaResponse{
GitRepository: server.Repository,
diff --git a/backend/server/server.go b/backend/server/server.go
index 7da468a..399ead0 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -14,6 +14,7 @@ import (
"github.com/go-chi/cors"
"github.com/go-chi/httprate"
"github.com/go-chi/render"
+ chiprometheus "github.com/toshi0607/chi-prometheus"
)
// Revision is the git commit, filled at build time
@@ -59,6 +60,12 @@ func New() (*Server, error) {
MaxAge: 300,
}))
+ // enable request latency tracking
+ os.Setenv(chiprometheus.EnvChiPrometheusLatencyBuckets, "10,25,50,100,300,500,1000,5000")
+ prom := chiprometheus.New("pronouns.cc")
+ s.Router.Use(prom.Handler)
+ prom.MustRegisterDefault()
+
// enable authentication for all routes (but don't require it)
s.Router.Use(s.maybeAuth)
diff --git a/docs/production.md b/docs/production.md
index 86f06ab..9afe530 100644
--- a/docs/production.md
+++ b/docs/production.md
@@ -22,7 +22,7 @@ one in the repository root (for the backend) and one in the frontend directory.
### Backend keys
-- `HMAC_KEY`: the key used to sign tokens. This should be a base64 string, you can generate one with `scripts/genkey`.
+- `HMAC_KEY`: the key used to sign tokens. This should be a base64 string, you can generate one with `go run -v . generate key` (or `./pronouns generate key` after building).
- `DATABASE_URL`: the URL for the PostgreSQL database.
- `REDIS`: the URL for the Redis database.
- `PORT` (int): the port the backend will listen on.
diff --git a/frontend/src/routes/@[username]/ReportButton.svelte b/frontend/src/routes/@[username]/ReportButton.svelte
index 4f55f9d..79dbc82 100644
--- a/frontend/src/routes/@[username]/ReportButton.svelte
+++ b/frontend/src/routes/@[username]/ReportButton.svelte
@@ -45,6 +45,9 @@
terms of service.
+
+ Note that we cannot take action on any reports that cannot be proven with just
+ the reported profile and any external pages linked on it.