Add follower and following collections
All checks were successful
/ docker (push) Successful in 4m34s

This commit is contained in:
Melody Becker 2025-05-11 18:28:51 +02:00
parent b75db5676b
commit af6ff2dd30
Signed by: mstar
SSH key fingerprint: SHA256:vkXfS9FG2pVNVfvDrzd1VW9n8VJzqqdKQGljxxX8uK8
11 changed files with 431 additions and 22 deletions

View file

@ -589,9 +589,15 @@ type IUserToUserRelationDo interface {
UnderlyingDB() *gorm.DB
schema.Tabler
GetFollowersForId(id string) (result []string, err error)
GetFollowerInboxesForId(id string) (result []string, err error)
GetFollowerApLinksPagedForId(id string, page int) (result []string, err error)
GetFollowingApLinksPagedForId(id string, page int) (result []string, err error)
CountFollowersForId(id string) (result int, err error)
CountFollowingForId(id string) (result int, err error)
}
// Get all inbox links for accounts following the user with the specified id
//
// SELECT u.inbox_link
// FROM user_to_user_relations r
// LEFT JOIN user_remote_links u
@ -600,7 +606,7 @@ type IUserToUserRelationDo interface {
//
// r.target_user_id = @id AND
// r.relation = 'follow'
func (u userToUserRelationDo) GetFollowersForId(id string) (result []string, err error) {
func (u userToUserRelationDo) GetFollowerInboxesForId(id string) (result []string, err error) {
var params []interface{}
var generateSQL strings.Builder
@ -614,6 +620,106 @@ func (u userToUserRelationDo) GetFollowersForId(id string) (result []string, err
return
}
// Get all Ids of the accounts following the user with the specified id
//
// SELECT u.ap_link
// FROM user_to_user_relations r
// LEFT JOIN user_remote_links u
// ON r.user_id = u.user_id
// WHERE
//
// r.target_user_id = @id AND
// r.relation = 'follow'
//
// LIMIT 50
// OFFSET @page * 50
func (u userToUserRelationDo) GetFollowerApLinksPagedForId(id string, page int) (result []string, err error) {
var params []interface{}
var generateSQL strings.Builder
params = append(params, id)
params = append(params, page)
generateSQL.WriteString("SELECT u.ap_link FROM user_to_user_relations r LEFT JOIN user_remote_links u ON r.user_id = u.user_id WHERE r.target_user_id = ? AND r.relation = 'follow' LIMIT 50 OFFSET ? * 50 ")
var executeSQL *gorm.DB
executeSQL = u.UnderlyingDB().Raw(generateSQL.String(), params...).Find(&result) // ignore_security_alert
err = executeSQL.Error
return
}
// Get all Ids of the accounts followed by the user with the specified id
//
// SELECT u.ap_link
// FROM user_to_user_relations r
// LEFT JOIN user_remote_links u
// ON r.user_id = u.user_id
// WHERE
//
// r.user_id = @id AND
// r.relation = 'follow'
//
// LIMIT 50
// OFFSET @page * 50
func (u userToUserRelationDo) GetFollowingApLinksPagedForId(id string, page int) (result []string, err error) {
var params []interface{}
var generateSQL strings.Builder
params = append(params, id)
params = append(params, page)
generateSQL.WriteString("SELECT u.ap_link FROM user_to_user_relations r LEFT JOIN user_remote_links u ON r.user_id = u.user_id WHERE r.user_id = ? AND r.relation = 'follow' LIMIT 50 OFFSET ? * 50 ")
var executeSQL *gorm.DB
executeSQL = u.UnderlyingDB().Raw(generateSQL.String(), params...).Find(&result) // ignore_security_alert
err = executeSQL.Error
return
}
// Count the accounts following the user with the specified id
//
// SELECT COUNT(*)
// FROM user_to_user_relations r
// WHERE
//
// r.target_user_id = @id AND
// r.relation = 'follow'
func (u userToUserRelationDo) CountFollowersForId(id string) (result int, err error) {
var params []interface{}
var generateSQL strings.Builder
params = append(params, id)
generateSQL.WriteString("SELECT COUNT(*) FROM user_to_user_relations r WHERE r.target_user_id = ? AND r.relation = 'follow' ")
var executeSQL *gorm.DB
executeSQL = u.UnderlyingDB().Raw(generateSQL.String(), params...).Take(&result) // ignore_security_alert
err = executeSQL.Error
return
}
// Count the accounts following the user with the specified id
//
// SELECT COUNT(*)
// FROM user_to_user_relations r
// WHERE
//
// r.user_id = @id AND
// r.relation = 'follow'
func (u userToUserRelationDo) CountFollowingForId(id string) (result int, err error) {
var params []interface{}
var generateSQL strings.Builder
params = append(params, id)
generateSQL.WriteString("SELECT COUNT(*) FROM user_to_user_relations r WHERE r.user_id = ? AND r.relation = 'follow' ")
var executeSQL *gorm.DB
executeSQL = u.UnderlyingDB().Raw(generateSQL.String(), params...).Take(&result) // ignore_security_alert
err = executeSQL.Error
return
}
func (u userToUserRelationDo) Debug() IUserToUserRelationDo {
return u.withDO(u.DO.Debug())
}