diff --git a/internal/api/model/instancev1.go b/internal/api/model/instancev1.go
index bec719941..b402cdefe 100644
--- a/internal/api/model/instancev1.go
+++ b/internal/api/model/instancev1.go
@@ -74,7 +74,9 @@ type InstanceV1 struct {
// URLs of interest for client applications.
URLs InstanceV1URLs `json:"urls,omitempty"`
// Statistics about the instance: number of posts, accounts, etc.
- Stats map[string]int `json:"stats,omitempty"`
+ // Values are pointers because we don't want to skip 0 values when
+ // rendering stats via web templates.
+ Stats map[string]*int `json:"stats,omitempty"`
// URL of the instance avatar/banner image.
// example: https://example.org/files/instance/thumbnail.jpeg
Thumbnail string `json:"thumbnail"`
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go
index f92f0bb65..592f36010 100644
--- a/internal/typeutils/internaltofrontend.go
+++ b/internal/typeutils/internaltofrontend.go
@@ -1024,24 +1024,24 @@ func (c *Converter) InstanceToAPIV1Instance(ctx context.Context, i *gtsmodel.Ins
instance.URLs.StreamingAPI = "wss://" + i.Domain
// statistics
- stats := make(map[string]int, 3)
+ stats := make(map[string]*int, 3)
userCount, err := c.state.DB.CountInstanceUsers(ctx, i.Domain)
if err != nil {
return nil, fmt.Errorf("InstanceToAPIV1Instance: db error getting counting instance users: %w", err)
}
- stats["user_count"] = userCount
+ stats["user_count"] = util.Ptr(userCount)
statusCount, err := c.state.DB.CountInstanceStatuses(ctx, i.Domain)
if err != nil {
return nil, fmt.Errorf("InstanceToAPIV1Instance: db error getting counting instance statuses: %w", err)
}
- stats["status_count"] = statusCount
+ stats["status_count"] = util.Ptr(statusCount)
domainCount, err := c.state.DB.CountInstanceDomains(ctx, i.Domain)
if err != nil {
return nil, fmt.Errorf("InstanceToAPIV1Instance: db error getting counting instance domains: %w", err)
}
- stats["domain_count"] = domainCount
+ stats["domain_count"] = util.Ptr(domainCount)
instance.Stats = stats
// thumbnail
diff --git a/web/template/page_header.tmpl b/web/template/page_header.tmpl
index dc727d144..5a2956883 100644
--- a/web/template/page_header.tmpl
+++ b/web/template/page_header.tmpl
@@ -26,7 +26,7 @@ Instance Logo
{{- end -}}
{{- define "strapUsers" -}}
-{{- with .instance.Stats.user_count -}}
+{{- with deref .instance.Stats.user_count -}}
{{- if eq . 1 -}}
{{- . -}} user
{{- else -}}
@@ -36,7 +36,7 @@ Instance Logo
{{- end -}}
{{- define "strapPosts" -}}
-{{- with .instance.Stats.status_count -}}
+{{- with deref .instance.Stats.status_count -}}
{{- if eq . 1 -}}
{{- . -}} post
{{- else -}}
@@ -46,7 +46,7 @@ Instance Logo
{{- end -}}
{{- define "strapInstances" -}}
-{{- with .instance.Stats.domain_count -}}
+{{- with deref .instance.Stats.domain_count -}}
{{- if eq . 1 -}}
{{- . -}} other instance
{{- else -}}