mirror of
1
Fork 0

[feature] Add local user and post count to nodeinfo responses (#1325)

* Add local user and post count to nodeinfo responses

This fixes #1307 (at least partially). The nodeinfo endpoint should now
return the total users on an instance, along with their post count.

* Update NodeInfoUsers docstring and swagger yaml file
This commit is contained in:
Sleep 2023-01-11 04:36:36 -06:00 committed by GitHub
parent d6487933c7
commit 3512325e46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 5 deletions

View File

@ -100,13 +100,22 @@ definitions:
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
NodeInfoUsage: NodeInfoUsage:
properties: properties:
localPosts:
format: int64
type: integer
x-go-name: LocalPosts
users: users:
$ref: '#/definitions/NodeInfoUsers' $ref: '#/definitions/NodeInfoUsers'
title: NodeInfoUsage represents usage information about this server, such as number of users. title: NodeInfoUsage represents usage information about this server, such as number of users.
type: object type: object
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
NodeInfoUsers: NodeInfoUsers:
title: NodeInfoUsers is a stub for usage information, currently empty. properties:
total:
format: int64
type: integer
x-go-name: Total
title: NodeInfoUsers represents aggregate information about the users on the server.
type: object type: object
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
Source: Source:

View File

@ -79,8 +79,11 @@ type NodeInfoServices struct {
// NodeInfoUsage represents usage information about this server, such as number of users. // NodeInfoUsage represents usage information about this server, such as number of users.
type NodeInfoUsage struct { type NodeInfoUsage struct {
Users NodeInfoUsers `json:"users"` Users NodeInfoUsers `json:"users"`
LocalPosts int `json:"localPosts"`
} }
// NodeInfoUsers is a stub for usage information, currently empty. // NodeInfoUsers represents aggregate information about the users on the server.
type NodeInfoUsers struct{} type NodeInfoUsers struct {
Total int `json:"total"`
}

View File

@ -55,6 +55,17 @@ func (p *processor) GetNodeInfo(ctx context.Context) (*apimodel.Nodeinfo, gtserr
openRegistration := config.GetAccountsRegistrationOpen() openRegistration := config.GetAccountsRegistrationOpen()
softwareVersion := config.GetSoftwareVersion() softwareVersion := config.GetSoftwareVersion()
host := config.GetHost()
userCount, err := p.db.CountInstanceUsers(ctx, host)
if err != nil {
return nil, gtserror.NewErrorInternalError(err, "Unable to query instance user count")
}
postCount, err := p.db.CountInstanceStatuses(ctx, host)
if err != nil {
return nil, gtserror.NewErrorInternalError(err, "Unable to query instance status count")
}
return &apimodel.Nodeinfo{ return &apimodel.Nodeinfo{
Version: nodeInfoVersion, Version: nodeInfoVersion,
Software: apimodel.NodeInfoSoftware{ Software: apimodel.NodeInfoSoftware{
@ -68,7 +79,10 @@ func (p *processor) GetNodeInfo(ctx context.Context) (*apimodel.Nodeinfo, gtserr
}, },
OpenRegistrations: openRegistration, OpenRegistrations: openRegistration,
Usage: apimodel.NodeInfoUsage{ Usage: apimodel.NodeInfoUsage{
Users: apimodel.NodeInfoUsers{}, Users: apimodel.NodeInfoUsers{
Total: userCount,
},
LocalPosts: postCount,
}, },
Metadata: make(map[string]interface{}), Metadata: make(map[string]interface{}),
}, nil }, nil