show all to avoid hidden posts

This commit is contained in:
Andre Medeiros 2022-05-26 18:56:53 -04:00
parent be343deab8
commit d8bd6dfb37
2 changed files with 27 additions and 4 deletions

View file

@ -3,6 +3,7 @@ package worker
import (
"context"
"fmt"
"math/rand"
"os"
"strconv"
"strings"
@ -191,10 +192,16 @@ func (sc *subredditsConsumer) Consume(delivery rmq.Delivery) {
zap.Int("page", page),
)
sps, err := sc.reddit.SubredditNew(sc,
i := rand.Intn(len(watchers))
watcher := watchers[i]
acc, _ := sc.accountRepo.GetByID(sc, watcher.AccountID)
rac := sc.reddit.NewAuthenticatedClient(acc.AccountID, acc.RefreshToken, acc.AccessToken)
sps, err := rac.SubredditNew(sc,
subreddit.Name,
reddit.WithQuery("before", before),
reddit.WithQuery("limit", "100"),
reddit.WithQuery("show", "all"),
)
if err != nil {
@ -252,9 +259,15 @@ func (sc *subredditsConsumer) Consume(delivery rmq.Delivery) {
zap.String("subreddit#name", subreddit.NormalizedName()),
)
{
sps, err := sc.reddit.SubredditHot(sc,
i := rand.Intn(len(watchers))
watcher := watchers[i]
acc, _ := sc.accountRepo.GetByID(sc, watcher.AccountID)
rac := sc.reddit.NewAuthenticatedClient(acc.AccountID, acc.RefreshToken, acc.AccessToken)
sps, err := rac.SubredditHot(sc,
subreddit.Name,
reddit.WithQuery("limit", "100"),
reddit.WithQuery("show", "all"),
)
if err != nil {

View file

@ -3,6 +3,7 @@ package worker
import (
"context"
"fmt"
"math/rand"
"os"
"sort"
"strconv"
@ -168,7 +169,12 @@ func (tc *trendingConsumer) Consume(delivery rmq.Delivery) {
return
}
tps, err := tc.reddit.SubredditTop(tc, subreddit.Name, reddit.WithQuery("t", "week"))
// Grab last month's top posts so we calculate a trending average
i := rand.Intn(len(watchers))
watcher := watchers[i]
rac := tc.reddit.NewAuthenticatedClient(watcher.Account.AccountID, watcher.Account.RefreshToken, watcher.Account.AccessToken)
tps, err := rac.SubredditTop(tc, subreddit.Name, reddit.WithQuery("t", "week"), reddit.WithQuery("show", "all"))
if err != nil {
tc.logger.Error("failed to fetch weeks's top posts",
zap.Error(err),
@ -219,7 +225,11 @@ func (tc *trendingConsumer) Consume(delivery rmq.Delivery) {
zap.Int64("score", medianScore),
)
hps, err := tc.reddit.SubredditHot(tc, subreddit.Name)
// Grab hot posts and filter out anything that's > 2 days old
i = rand.Intn(len(watchers))
watcher = watchers[i]
rac = tc.reddit.NewAuthenticatedClient(watcher.Account.AccountID, watcher.Account.RefreshToken, watcher.Account.AccessToken)
hps, err := tc.reddit.SubredditHot(tc, subreddit.Name, reddit.WithQuery("show", "all"))
if err != nil {
tc.logger.Error("failed to fetch hot posts",
zap.Error(err),