parent
79c30fdc69
commit
0e97285e0a
@ -1,49 +0,0 @@
|
|||||||
package cache
|
|
||||||
|
|
||||||
import (
|
|
||||||
"Open_IM/pkg/utils"
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"github.com/dtm-labs/rockscache"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetCache[T any](ctx context.Context, rcClient *rockscache.Client, key string, expire time.Duration, fn func(ctx context.Context) (T, error)) (T, error) {
|
|
||||||
var t T
|
|
||||||
var write bool
|
|
||||||
v, err := rcClient.Fetch(key, expire, func() (s string, err error) {
|
|
||||||
t, err = fn(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
bs, err := json.Marshal(t)
|
|
||||||
if err != nil {
|
|
||||||
return "", utils.Wrap(err, "")
|
|
||||||
}
|
|
||||||
write = true
|
|
||||||
return string(bs), nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return t, err
|
|
||||||
}
|
|
||||||
if write {
|
|
||||||
return t, nil
|
|
||||||
}
|
|
||||||
err = json.Unmarshal([]byte(v), &t)
|
|
||||||
if err != nil {
|
|
||||||
return t, utils.Wrap(err, "")
|
|
||||||
}
|
|
||||||
return t, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetCacheFor[E any, T any](ctx context.Context, list []E, fn func(ctx context.Context, item E) (T, error)) ([]T, error) {
|
|
||||||
rs := make([]T, 0, len(list))
|
|
||||||
for _, e := range list {
|
|
||||||
r, err := fn(ctx, e)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
rs = append(rs, r)
|
|
||||||
}
|
|
||||||
return rs, nil
|
|
||||||
}
|
|
@ -1 +1,21 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
pbMsg "Open_IM/pkg/proto/msg"
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MsgInterface interface {
|
||||||
|
BatchInsertChat2DB(ctx context.Context, userID string, msgList []*pbMsg.MsgDataToMQ, currentMaxSeq uint64) error
|
||||||
|
BatchInsertChat2Cache(ctx context.Context, insertID string, msgList []*pbMsg.MsgDataToMQ) (error, uint64)
|
||||||
|
DelMsgBySeqList(ctx context.Context, userID string, seqList []uint32) (totalUnExistSeqList []uint32, err error)
|
||||||
|
DelMsgLogic(ctx context.Context, uid string, seqList []uint32) error
|
||||||
|
DelMsgBySeqListInOneDoc(ctx context.Context, docID string, seqList []uint32) (unExistSeqList []uint32, err error)
|
||||||
|
ReplaceMsgToBlankByIndex(suffixID string, index int) (replaceMaxSeq uint32, err error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type MsgDatabaseInterface interface {
|
||||||
|
BatchInsertChat2DB(ctx context.Context, userID string, msgList []*pbMsg.MsgDataToMQ, currentMaxSeq uint64) error
|
||||||
|
BatchInsertChat2Cache(ctx context.Context, insertID string, msgList []*pbMsg.MsgDataToMQ) (error, uint64)
|
||||||
|
DelMsgBySeqList(ctx context.Context, userID string, seqList []uint32) (totalUnExistSeqList []uint32, err error)
|
||||||
|
}
|
||||||
|
Loading…
Reference in new issue