mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-10-31 22:40:01 +00:00
[bugfix] Use ptr for instance stats entries to avoid skipping 0 values (#2666)
* [bugfix] Use ptr for instance stats entries to avoid skipping 0 values * comment explaining why stats values are pointers
This commit is contained in:
parent
0554550acb
commit
d10226e912
3 changed files with 10 additions and 8 deletions
|
@ -74,7 +74,9 @@ type InstanceV1 struct {
|
||||||
// URLs of interest for client applications.
|
// URLs of interest for client applications.
|
||||||
URLs InstanceV1URLs `json:"urls,omitempty"`
|
URLs InstanceV1URLs `json:"urls,omitempty"`
|
||||||
// Statistics about the instance: number of posts, accounts, etc.
|
// 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.
|
// URL of the instance avatar/banner image.
|
||||||
// example: https://example.org/files/instance/thumbnail.jpeg
|
// example: https://example.org/files/instance/thumbnail.jpeg
|
||||||
Thumbnail string `json:"thumbnail"`
|
Thumbnail string `json:"thumbnail"`
|
||||||
|
|
|
@ -1024,24 +1024,24 @@ func (c *Converter) InstanceToAPIV1Instance(ctx context.Context, i *gtsmodel.Ins
|
||||||
instance.URLs.StreamingAPI = "wss://" + i.Domain
|
instance.URLs.StreamingAPI = "wss://" + i.Domain
|
||||||
|
|
||||||
// statistics
|
// statistics
|
||||||
stats := make(map[string]int, 3)
|
stats := make(map[string]*int, 3)
|
||||||
userCount, err := c.state.DB.CountInstanceUsers(ctx, i.Domain)
|
userCount, err := c.state.DB.CountInstanceUsers(ctx, i.Domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("InstanceToAPIV1Instance: db error getting counting instance users: %w", err)
|
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)
|
statusCount, err := c.state.DB.CountInstanceStatuses(ctx, i.Domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("InstanceToAPIV1Instance: db error getting counting instance statuses: %w", err)
|
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)
|
domainCount, err := c.state.DB.CountInstanceDomains(ctx, i.Domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("InstanceToAPIV1Instance: db error getting counting instance domains: %w", err)
|
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
|
instance.Stats = stats
|
||||||
|
|
||||||
// thumbnail
|
// thumbnail
|
||||||
|
|
|
@ -26,7 +26,7 @@ Instance Logo
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "strapUsers" -}}
|
{{- define "strapUsers" -}}
|
||||||
{{- with .instance.Stats.user_count -}}
|
{{- with deref .instance.Stats.user_count -}}
|
||||||
{{- if eq . 1 -}}
|
{{- if eq . 1 -}}
|
||||||
<span class="count">{{- . -}}</span> user
|
<span class="count">{{- . -}}</span> user
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
|
@ -36,7 +36,7 @@ Instance Logo
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "strapPosts" -}}
|
{{- define "strapPosts" -}}
|
||||||
{{- with .instance.Stats.status_count -}}
|
{{- with deref .instance.Stats.status_count -}}
|
||||||
{{- if eq . 1 -}}
|
{{- if eq . 1 -}}
|
||||||
<span class="count">{{- . -}}</span> post
|
<span class="count">{{- . -}}</span> post
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
|
@ -46,7 +46,7 @@ Instance Logo
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "strapInstances" -}}
|
{{- define "strapInstances" -}}
|
||||||
{{- with .instance.Stats.domain_count -}}
|
{{- with deref .instance.Stats.domain_count -}}
|
||||||
{{- if eq . 1 -}}
|
{{- if eq . 1 -}}
|
||||||
<span class="count">{{- . -}}</span> other instance
|
<span class="count">{{- . -}}</span> other instance
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
|
|
Loading…
Reference in a new issue