replace proto.Clone calls (#3024)
* replace proto.Clone calls * deps * tests
This commit is contained in:
@@ -20,9 +20,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/thoas/go-funk"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/utils"
|
||||
)
|
||||
|
||||
// encapsulates CRUD operations for room settings
|
||||
@@ -184,7 +184,7 @@ func (s *LocalStore) StoreAgentDispatch(ctx context.Context, dispatch *livekit.A
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
clone := proto.Clone(dispatch).(*livekit.AgentDispatch)
|
||||
clone := utils.CloneProto(dispatch)
|
||||
if clone.State != nil {
|
||||
clone.State.Jobs = nil
|
||||
}
|
||||
@@ -224,14 +224,14 @@ func (s *LocalStore) ListAgentDispatches(ctx context.Context, roomName livekit.R
|
||||
var js []*livekit.Job
|
||||
if agentJobs != nil {
|
||||
for _, j := range agentJobs {
|
||||
js = append(js, proto.Clone(j).(*livekit.Job))
|
||||
js = append(js, utils.CloneProto(j))
|
||||
}
|
||||
}
|
||||
var ds []*livekit.AgentDispatch
|
||||
|
||||
m := make(map[string]*livekit.AgentDispatch)
|
||||
for _, d := range agentDispatches {
|
||||
clone := proto.Clone(d).(*livekit.AgentDispatch)
|
||||
clone := utils.CloneProto(d)
|
||||
m[d.Id] = clone
|
||||
ds = append(ds, clone)
|
||||
}
|
||||
@@ -239,7 +239,7 @@ func (s *LocalStore) ListAgentDispatches(ctx context.Context, roomName livekit.R
|
||||
for _, j := range js {
|
||||
d := m[j.DispatchId]
|
||||
if d != nil {
|
||||
d.State.Jobs = append(d.State.Jobs, proto.Clone(j).(*livekit.Job))
|
||||
d.State.Jobs = append(d.State.Jobs, utils.CloneProto(j))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ func (s *LocalStore) StoreAgentJob(ctx context.Context, job *livekit.Job) error
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
clone := proto.Clone(job).(*livekit.Job)
|
||||
clone := utils.CloneProto(job)
|
||||
clone.Room = nil
|
||||
if clone.Participant != nil {
|
||||
clone.Participant = &livekit.ParticipantInfo{
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"github.com/livekit/protocol/ingress"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/livekit/protocol/utils/guid"
|
||||
"github.com/livekit/psrpc"
|
||||
|
||||
@@ -527,7 +528,7 @@ func (s *RedisStore) storeIngress(_ context.Context, info *livekit.IngressInfo)
|
||||
}
|
||||
|
||||
// ignore state
|
||||
infoCopy := proto.Clone(info).(*livekit.IngressInfo)
|
||||
infoCopy := utils.CloneProto(info)
|
||||
infoCopy.State = nil
|
||||
|
||||
data, err := proto.Marshal(infoCopy)
|
||||
@@ -830,7 +831,7 @@ func (s *RedisStore) DeleteIngress(_ context.Context, info *livekit.IngressInfo)
|
||||
}
|
||||
|
||||
func (s *RedisStore) StoreAgentDispatch(_ context.Context, dispatch *livekit.AgentDispatch) error {
|
||||
di := proto.Clone(dispatch).(*livekit.AgentDispatch)
|
||||
di := utils.CloneProto(dispatch)
|
||||
|
||||
// Do not store jobs with the dispatch
|
||||
if di.State != nil {
|
||||
@@ -893,7 +894,7 @@ func (s *RedisStore) StoreAgentJob(_ context.Context, job *livekit.Job) error {
|
||||
|
||||
key := AgentJobPrefix + string(job.Room.Name)
|
||||
|
||||
jb := proto.Clone(job).(*livekit.Job)
|
||||
jb := utils.CloneProto(job)
|
||||
|
||||
// Do not store room with the job
|
||||
jb.Room = nil
|
||||
|
||||
@@ -343,7 +343,7 @@ func TestAgentStore(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(rd))
|
||||
|
||||
expected := proto.Clone(ad).(*livekit.AgentDispatch)
|
||||
expected := utils.CloneProto(ad)
|
||||
expected.State.Jobs = nil
|
||||
require.True(t, proto.Equal(expected, rd[0]))
|
||||
|
||||
@@ -354,7 +354,7 @@ func TestAgentStore(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(rd))
|
||||
|
||||
expected = proto.Clone(ad).(*livekit.AgentDispatch)
|
||||
expected = utils.CloneProto(ad)
|
||||
expected.State.Jobs[0].Room = nil
|
||||
expected.State.Jobs[0].Participant = &livekit.ParticipantInfo{
|
||||
Identity: "identity",
|
||||
@@ -368,7 +368,7 @@ func TestAgentStore(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(rd))
|
||||
|
||||
expected = proto.Clone(ad).(*livekit.AgentDispatch)
|
||||
expected = utils.CloneProto(ad)
|
||||
expected.State.Jobs = nil
|
||||
require.True(t, proto.Equal(expected, rd[0]))
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
@@ -211,7 +209,7 @@ func (r *StandardRoomAllocator) applyNamedRoomConfiguration(req *livekit.CreateR
|
||||
return req, psrpc.NewErrorf(psrpc.InvalidArgument, "unknown room confguration in create room request")
|
||||
}
|
||||
|
||||
clone := proto.Clone(req).(*livekit.CreateRoomRequest)
|
||||
clone := utils.CloneProto(req)
|
||||
|
||||
// Request overwrites conf
|
||||
if clone.EmptyTimeout == 0 {
|
||||
@@ -224,10 +222,10 @@ func (r *StandardRoomAllocator) applyNamedRoomConfiguration(req *livekit.CreateR
|
||||
clone.MaxParticipants = conf.MaxParticipants
|
||||
}
|
||||
if clone.Egress == nil {
|
||||
clone.Egress = proto.Clone(conf.Egress).(*livekit.RoomEgress)
|
||||
clone.Egress = utils.CloneProto(conf.Egress)
|
||||
}
|
||||
if clone.Agent == nil {
|
||||
clone.Agent = proto.Clone(conf.Agent).(*livekit.RoomAgent)
|
||||
clone.Agent = utils.CloneProto(conf.Agent)
|
||||
}
|
||||
if clone.MinPlayoutDelay == 0 {
|
||||
clone.MinPlayoutDelay = conf.MinPlayoutDelay
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/twitchtv/twirp"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/routing"
|
||||
@@ -30,6 +29,7 @@ import (
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/rpc"
|
||||
"github.com/livekit/protocol/utils"
|
||||
)
|
||||
|
||||
type RoomService struct {
|
||||
@@ -323,7 +323,7 @@ func redactCreateRoomRequest(req *livekit.CreateRoomRequest) *livekit.CreateRoom
|
||||
return req
|
||||
}
|
||||
|
||||
clone := proto.Clone(req).(*livekit.CreateRoomRequest)
|
||||
clone := utils.CloneProto(req)
|
||||
|
||||
if clone.Egress.Room != nil {
|
||||
egress.RedactEncodedOutputs(clone.Egress.Room)
|
||||
|
||||
Reference in New Issue
Block a user