1
0
Fork 0

Compare commits

...

8 Commits

Author SHA1 Message Date
BreadMakesYouFat f60646f959
Merge 7fb12fe84f into 494b856c9e 2023-11-05 10:01:30 -07:00
mrusme 494b856c9e
Merge pull request #48 from mrusme/dependabot/go_modules/golang.org/x/image-0.10.0
Bump golang.org/x/image from 0.9.0 to 0.10.0
2023-11-05 15:19:16 +00:00
dependabot[bot] cdf54c70e9
Bump golang.org/x/image from 0.9.0 to 0.10.0
Bumps [golang.org/x/image](https://github.com/golang/image) from 0.9.0 to 0.10.0.
- [Commits](https://github.com/golang/image/compare/v0.9.0...v0.10.0)

---
updated-dependencies:
- dependency-name: golang.org/x/image
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-02 21:38:11 +00:00
BreadMakesYouFat 7fb12fe84f Lemmy ListPosts query optimization 2023-06-26 15:38:10 -04:00
BreadMakesYouFat 30fb8e80e9 urlparse for lemmy community full name 2023-06-26 15:38:10 -04:00
BreadMakesYouFat 3a7d2af100 Limit subscription query (configurable) 2023-06-26 15:38:10 -04:00
BreadMakesYouFat fb84533aea Fullnames for lemmy instances: catalog@instance 2023-06-26 15:38:10 -04:00
BreadMakesYouFat a047a392bd Lemmy filter improvements
resolves mrusme/neonmodem#32 Filter for lemmy communities
resolves mrusme/neonmodem#37 Keep lemmy results 50 but query specific community
Show all subscribed lemmy communities + re-query for results from that specific community when selected
2023-06-26 15:38:10 -04:00
5 changed files with 73 additions and 24 deletions

2
go.mod
View File

@ -62,7 +62,7 @@ require (
github.com/yuin/goldmark-emoji v1.0.2 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/image v0.9.0 // indirect
golang.org/x/image v0.10.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.13.0 // indirect

4
go.sum
View File

@ -322,8 +322,8 @@ golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMx
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20191206065243-da761ea9ff43/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.9.0 h1:QrzfX26snvCM20hIhBwuHI/ThTg18b/+kcKdXHvnR+g=
golang.org/x/image v0.9.0/go.mod h1:jtrku+n79PfroUbvDdeUWMAI+heR786BofxrbiSF+J0=
golang.org/x/image v0.10.0 h1:gXjUUtwtx5yOE0VKWq1CH4IJAClq4UGgUA3i+rpON9M=
golang.org/x/image v0.10.0/go.mod h1:jtrku+n79PfroUbvDdeUWMAI+heR786BofxrbiSF+J0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=

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

@ -18,6 +18,7 @@ import (
"go.uber.org/zap"
)
type System struct {
ID int
config map[string]interface{}
@ -154,36 +155,79 @@ func (sys *System) Load() error {
return nil
}
func (sys *System) ListForums() ([]forum.Forum, error) {
resp, err := sys.client.Communities(context.Background(), types.ListCommunities{
Type: types.NewOptional(types.ListingTypeSubscribed),
})
func communityFullname(community types.CommunitySafe) (communityName string) {
url, err := url.Parse(community.ActorID)
if err != nil {
return []forum.Forum{}, err
return community.Name
} else {
return community.Name + "@" + url.Host
}
}
func (sys *System) ListForums() ([]forum.Forum, error) {
var models []forum.Forum
for _, i := range resp.Communities {
models = append(models, forum.Forum{
ID: strconv.Itoa(i.Community.ID),
Name: i.Community.Name,
Info: i.Community.Description.ValueOr(i.Community.Title),
SysIDX: sys.ID,
})
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(page)),
Limit: types.NewOptional(int64(queryLimit)),
})
if err != nil {
break
}
if len(resp.Communities) == 0 {
break
}
for _, i := range resp.Communities {
models = append(models, forum.Forum{
ID: strconv.Itoa(i.Community.ID),
Name: communityFullname(i.Community),
Info: i.Community.Description.ValueOr(i.Community.Title),
SysIDX: sys.ID,
})
}
page += 1
}
return models, nil
}
func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
resp, err := sys.client.Posts(context.Background(), types.GetPosts{
Type: types.NewOptional(types.ListingTypeSubscribed),
Sort: types.NewOptional(types.SortTypeNew),
Limit: types.NewOptional(int64(50)),
})
var models []post.Post
var showAll bool
var err error
communityID, err := strconv.Atoi(forumID)
if err != nil {
showAll = true
}
var getPosts types.GetPosts
if showAll {
getPosts = types.GetPosts{
Type: types.NewOptional(types.ListingTypeSubscribed),
Sort: types.NewOptional(types.SortTypeNew),
Limit: types.NewOptional(int64(50)),
}
} else {
getPosts = types.GetPosts{
Type: types.NewOptional(types.ListingTypeSubscribed),
Sort: types.NewOptional(types.SortTypeNew),
Limit: types.NewOptional(int64(50)),
CommunityID: types.NewOptional(communityID),
}
}
resp, err := sys.client.Posts(context.Background(), getPosts)
if err != nil {
return []post.Post{}, err
}
@ -191,7 +235,6 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
cfg := sys.GetConfig()
baseURL := cfg["url"].(string)
var models []post.Post
for _, i := range resp.Posts {
t := "post"
body := i.Post.Body.ValueOr("")
@ -223,7 +266,7 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
Forum: forum.Forum{
ID: strconv.Itoa(i.Post.CommunityID),
Name: i.Community.Name,
Name: communityFullname(i.Community),
SysIDX: sys.ID,
},