MCPcopy Index your code
hub / github.com/PasarGuard/node / SyncUsersChunked

Method SyncUsersChunked

controller/rpc/user.go:45–88  ·  view source on GitHub ↗
(stream grpc.ClientStreamingServer[common.UsersChunk, common.Empty])

Source from the content-addressed store, hash-verified

43}
44
45func (s *Service) SyncUsersChunked(stream grpc.ClientStreamingServer[common.UsersChunk, common.Empty]) error {
46 chunks := make(map[uint64][]*common.User)
47 var (
48 lastIndex uint64
49 sawLast bool
50 )
51
52 for {
53 chunk, err := stream.Recv()
54 if errors.Is(err, io.EOF) {
55 break
56 }
57 if err != nil {
58 return status.Errorf(codes.Internal, "failed to receive chunk: %v", err)
59 }
60
61 chunks[chunk.GetIndex()] = append(chunks[chunk.GetIndex()], chunk.GetUsers()...)
62
63 if chunk.GetLast() {
64 sawLast = true
65 lastIndex = chunk.GetIndex()
66 break
67 }
68 }
69
70 users, err := controller.BuildUsersFromChunks(chunks, lastIndex, sawLast)
71 if err != nil {
72 return status.Error(codes.InvalidArgument, err.Error())
73 }
74
75 // Large chunk: update in-memory then restart (no API calls).
76 if len(users) > 100 {
77 if err := s.Backend().UpdateUsersAndRestart(stream.Context(), users); err != nil {
78 return status.Errorf(codes.Internal, "failed to update users: %v", err)
79 }
80 } else {
81 // Small chunk: update via API without restart.
82 if err := s.Backend().UpdateUsers(stream.Context(), users); err != nil {
83 return status.Errorf(codes.Internal, "failed to update users: %v", err)
84 }
85 }
86
87 return stream.SendAndClose(&common.Empty{})
88}

Callers

nothing calls this directly

Implementers 1

Controllercontroller/controller.go

Calls 8

BuildUsersFromChunksFunction · 0.92
GetIndexMethod · 0.80
GetLastMethod · 0.80
ErrorMethod · 0.80
BackendMethod · 0.80
UpdateUsersAndRestartMethod · 0.65
UpdateUsersMethod · 0.65
GetUsersMethod · 0.45

Tested by

no test coverage detected