Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ env:
jobs:
ci:
name: API Lint, Build, Test, Deploy
runs-on: aws-runner
runs-on: seventv
env:
GOLANGCI_LINT_CACHE: /home/runner/.cache/golangci-lint
concurrency:
Expand Down Expand Up @@ -144,7 +144,7 @@ jobs:
validate:
name: API Deploy Validation
needs: ci
runs-on: ubuntu-latest
runs-on: seventv
permissions:
pull-requests: write
defaults:
Expand Down
2 changes: 1 addition & 1 deletion data/mutate/emote_set.active_emote.mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (m *Mutate) EditEmotesInSet(ctx context.Context, esb *structures.EmoteSetBu
TargetID: tgt.emote.ID,
Wish: "personal_use",
})
if err := m.SendModRequestMessage(ctx, mb); err != nil {
if err := m.SendModRequestMessage(ctx, mb, 0); err != nil {
z.Errorw("failed to send personal_use mod request message", "error", err)
}
}
Expand Down
3 changes: 2 additions & 1 deletion data/mutate/message.mod_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
)

func (m *Mutate) SendModRequestMessage(ctx context.Context, mb *structures.MessageBuilder[structures.MessageDataModRequest]) error {
func (m *Mutate) SendModRequestMessage(ctx context.Context, mb *structures.MessageBuilder[structures.MessageDataModRequest], weight int32) error {
if mb == nil {
return errors.ErrInternalIncompleteMutation()
} else if mb.IsTainted() {
Expand Down Expand Up @@ -60,6 +60,7 @@ func (m *Mutate) SendModRequestMessage(ctx context.Context, mb *structures.Messa
MessageID: msgID,
Kind: structures.MessageKindModRequest,
Timestamp: time.Now(),
Weight: weight,
})

mb.MarkAsTainted()
Expand Down
32 changes: 29 additions & 3 deletions data/query/query.messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ package query

import (
"context"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"strconv"
"sync"
"time"

"github.com/seventv/common/errors"
"github.com/seventv/common/mongo"
"github.com/seventv/common/redis"
"github.com/seventv/common/structures/v3"
"github.com/seventv/common/structures/v3/aggregations"
"go.mongodb.org/mongo-driver/bson"
Expand Down Expand Up @@ -89,7 +95,7 @@ func (q *Query) Messages(ctx context.Context, filter bson.M, opt MessageQueryOpt
qr := &QueryResult[structures.Message[bson.Raw]]{}

if opt.Sort == nil {
opt.Sort = bson.M{"_id": -1}
opt.Sort = bson.D{{Key: "_id", Value: -1}}
}

if opt.UnreadOnly {
Expand Down Expand Up @@ -119,9 +125,26 @@ func (q *Query) Messages(ctx context.Context, filter bson.M, opt MessageQueryOpt
wg := sync.WaitGroup{}
wg.Add(1)

h := sha256.New()

fb, err := json.Marshal(filter)
if err == nil {
h.Write(fb)
}

rKey := q.redis.ComposeKey("api", "messages", hex.EncodeToString(h.Sum(nil)), "count")

go func() {
defer wg.Done()

count, err := q.redis.Get(ctx, rKey)
if err != redis.Nil {
n, _ := strconv.ParseInt(count, 10, 64)

qr.setTotal(n)
return
}

cur, err := q.mongo.Collection(mongo.CollectionNameMessagesRead).Aggregate(ctx, aggregations.Combine(
matcherPipeline,
func() mongo.Pipeline {
Expand Down Expand Up @@ -158,6 +181,8 @@ func (q *Query) Messages(ctx context.Context, filter bson.M, opt MessageQueryOpt
}

qr.setTotal(v.Count)

q.redis.SetEX(ctx, rKey, v.Count, time.Minute*5)
}()

cur, err := q.mongo.Collection(mongo.CollectionNameMessagesRead).Aggregate(ctx, aggregations.Combine(
Expand All @@ -180,6 +205,7 @@ func (q *Query) Messages(ctx context.Context, filter bson.M, opt MessageQueryOpt
bson.M{
"timestamp": "$timestamp",
"read": "$read",
"weight": "$weight",
},
},
},
Expand Down Expand Up @@ -233,7 +259,7 @@ type ModRequestMessagesQueryOptions struct {
Targets map[structures.ObjectKind]bool
TargetIDs []primitive.ObjectID
Filter bson.M
Sort bson.M
Sort bson.D
Limit int
SkipPermissionCheck bool
}
Expand All @@ -244,5 +270,5 @@ type MessageQueryOptions struct {
UnreadOnly bool
MessageFilter bson.M
FilterRecipients []primitive.ObjectID
Sort bson.M
Sort bson.D
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/nats-io/nats.go v1.28.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/prometheus/client_golang v1.14.0
github.com/seventv/common v0.0.0-20231206031419-1ba3f2c093f6
github.com/seventv/common v0.0.0-20231206143048-3810874764f0
github.com/seventv/compactdisc v0.0.0-20221006190906-ccfe99954e48
github.com/seventv/image-processor/go v0.0.0-20221128171540-d050701ac324
github.com/seventv/message-queue/go v0.0.0-20231201171845-1bb9d5db6881
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ github.com/seventv/common v0.0.0-20231202052307-1d4dd4479600 h1:qwu6BlOxmKPBe9S8
github.com/seventv/common v0.0.0-20231202052307-1d4dd4479600/go.mod h1:jHHFe3uNMyzb/ReDqMvaI/A1euvV/PW/G+2PhcWQqWw=
github.com/seventv/common v0.0.0-20231206031419-1ba3f2c093f6 h1:A1aHPZxG5XU+rqpuWFm5oeUaV/CwcjVfFmdzdw7Kpzw=
github.com/seventv/common v0.0.0-20231206031419-1ba3f2c093f6/go.mod h1:jHHFe3uNMyzb/ReDqMvaI/A1euvV/PW/G+2PhcWQqWw=
github.com/seventv/common v0.0.0-20231206143048-3810874764f0 h1:mcNiALWjv9uHzRn8E5LWor0JRTs8iJGkVle/zaNLKaE=
github.com/seventv/common v0.0.0-20231206143048-3810874764f0/go.mod h1:jHHFe3uNMyzb/ReDqMvaI/A1euvV/PW/G+2PhcWQqWw=
github.com/seventv/compactdisc v0.0.0-20221006190906-ccfe99954e48 h1:IqWrtt/yob45YnOQ5Wwkbf8qP22eKVtg0WzfyEkGnFg=
github.com/seventv/compactdisc v0.0.0-20221006190906-ccfe99954e48/go.mod h1:T+ldp0YQe03s44+A5HHHI/jB3ZmWqOIaNouEqAS+1Dk=
github.com/seventv/image-processor/go v0.0.0-20221128171540-d050701ac324 h1:iU3wWepRTbkNoTAPR23m6TAW6Yb9pOMCYVr0K++OBAw=
Expand Down
2 changes: 1 addition & 1 deletion internal/api/gql/v3/resolvers/query/query.mod_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (r *Resolver) ModRequests(ctx context.Context, afterIDArg *primitive.Object
Actor: &actor,
Filter: match,
Limit: limit,
Sort: bson.M{"_id": 1},
Sort: bson.D{{Key: "weight", Value: -1}, {Key: "_id", Value: 1}}, // bson.M{"_id": 1, "weight": -1},
Targets: map[structures.ObjectKind]bool{
structures.ObjectKindEmote: true,
},
Expand Down
5 changes: 4 additions & 1 deletion internal/api/rest/v3/routes/emotes/emotes.process.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,10 @@ func (epl *EmoteProcessingListener) HandleResultEvent(ctx context.Context, evt t
ActorCountryName: actorCountryName,
ActorCountryCode: actorCountryCode,
})
if err = epl.Ctx.Inst().Mutate.SendModRequestMessage(ctx, mb); err != nil {

rsWeight := utils.Ternary(emoteOwner.HasPermission(structures.RolePermissionFeatureMessagingPriority), 100, 0)

if err = epl.Ctx.Inst().Mutate.SendModRequestMessage(ctx, mb, int32(rsWeight)); err != nil {
zap.S().Errorw("failed to send mod request message for new emote",
"error", err,
"EMOTE_ID", id,
Expand Down