1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-06-23 06:35:24 +00:00

Limit subscription query (configurable)

This commit is contained in:
BreadMakesYouFat 2023-06-26 15:31:45 -04:00
parent fb84533aea
commit 3a7d2af100
3 changed files with 19 additions and 3 deletions

View File

@ -50,5 +50,7 @@ func (sys *System) Connect(sysURL string) error {
sys.config["url"] = sysURL
sys.config["credentials"] = credentials
sys.config["MaxSubscriptions"] = MaxSubscriptions
return nil
}

4
system/lemmy/constant.go Normal file
View File

@ -0,0 +1,4 @@
package lemmy
// Limit the maximum number of subscription queries
const MaxSubscriptions = 10000

View File

@ -19,6 +19,7 @@ import (
"go.uber.org/zap"
)
type System struct {
ID int
config map[string]interface{}
@ -178,11 +179,19 @@ func communityFullname(community types.CommunitySafe) (communityName string) {
func (sys *System) ListForums() ([]forum.Forum, error) {
var models []forum.Forum
for j := 1; j < 100; j++ {
var maxSubscriptions int
if sys.config["MaxSubscriptions"] != nil {
maxSubscriptions = sys.config["MaxSubscriptions"].(int)
} else {
maxSubscriptions = MaxSubscriptions
}
page := 1
queryLimit := 50
for page < maxSubscriptions {
resp, err := sys.client.Communities(context.Background(), types.ListCommunities{
Type: types.NewOptional(types.ListingTypeSubscribed),
Page: types.NewOptional(int64(j)),
Limit: types.NewOptional(int64(50)),
Page: types.NewOptional(int64(page)),
Limit: types.NewOptional(int64(queryLimit)),
})
if err != nil {
break
@ -200,6 +209,7 @@ func (sys *System) ListForums() ([]forum.Forum, error) {
SysIDX: sys.ID,
})
}
page += 1
}
return models, nil
}