Skip to content

Commit

Permalink
Clean up converter
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins committed Dec 13, 2023
1 parent 56fb0eb commit c93f27f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 45 deletions.
25 changes: 13 additions & 12 deletions admin/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,39 +174,39 @@ func (c *Client) SignUp(
func (c *Client) CreateProject(ctx context.Context, name string) (*types.Project, error) {
response, err := c.client.CreateProject(
ctx,
connect.NewRequest(&api.CreateProjectRequest{
Name: name,
},
))
connect.NewRequest(&api.CreateProjectRequest{Name: name}),
)
if err != nil {
return nil, err
}

return converter.FromProject(response.Msg.Project)
return converter.FromProject(response.Msg.Project), nil
}

// GetProject gets the project by name.
func (c *Client) GetProject(ctx context.Context, name string) (*types.Project, error) {
response, err := c.client.GetProject(
ctx,
connect.NewRequest(&api.GetProjectRequest{Name: name}))
connect.NewRequest(&api.GetProjectRequest{Name: name}),
)
if err != nil {
return nil, err
}

return converter.FromProject(response.Msg.Project)
return converter.FromProject(response.Msg.Project), nil
}

// ListProjects lists all projects.
func (c *Client) ListProjects(ctx context.Context) ([]*types.Project, error) {
response, err := c.client.ListProjects(
ctx,
connect.NewRequest(&api.ListProjectsRequest{}))
connect.NewRequest(&api.ListProjectsRequest{}),
)
if err != nil {
return nil, err
}

return converter.FromProjects(response.Msg.Projects)
return converter.FromProjects(response.Msg.Projects), nil
}

// UpdateProject updates an existing project.
Expand All @@ -228,7 +228,7 @@ func (c *Client) UpdateProject(
return nil, err
}

return converter.FromProject(response.Msg.Project)
return converter.FromProject(response.Msg.Project), nil
}

// ListDocuments lists documents.
Expand All @@ -254,7 +254,7 @@ func (c *Client) ListDocuments(
return nil, err
}

return converter.FromDocumentSummaries(response.Msg.Documents)
return converter.FromDocumentSummaries(response.Msg.Documents), nil
}

// RemoveDocument removes a document of the given key.
Expand All @@ -277,7 +277,8 @@ func (c *Client) RemoveDocument(
DocumentKey: documentKey,
Force: force,
},
), apiKey, documentKey))
), apiKey, documentKey),
)
return err
}

Expand Down
44 changes: 15 additions & 29 deletions api/converter/from_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,16 @@ func FromUser(pbUser *api.User) (*types.User, error) {
}

// FromProjects converts the given Protobuf formats to model format.
func FromProjects(pbProjects []*api.Project) ([]*types.Project, error) {
func FromProjects(pbProjects []*api.Project) []*types.Project {
var projects []*types.Project
for _, pbProject := range pbProjects {
project, err := FromProject(pbProject)
if err != nil {
return nil, err
}
projects = append(projects, project)
projects = append(projects, FromProject(pbProject))
}
return projects, nil
return projects
}

// FromProject converts the given Protobuf formats to model format.
func FromProject(pbProject *api.Project) (*types.Project, error) {
createdAt := pbProject.CreatedAt.AsTime()
updatedAt := pbProject.UpdatedAt.AsTime()

func FromProject(pbProject *api.Project) *types.Project {
return &types.Project{
ID: types.ID(pbProject.Id),
Name: pbProject.Name,
Expand All @@ -66,37 +59,30 @@ func FromProject(pbProject *api.Project) (*types.Project, error) {
ClientDeactivateThreshold: pbProject.ClientDeactivateThreshold,
PublicKey: pbProject.PublicKey,
SecretKey: pbProject.SecretKey,
CreatedAt: createdAt,
UpdatedAt: updatedAt,
}, nil
CreatedAt: pbProject.CreatedAt.AsTime(),
UpdatedAt: pbProject.UpdatedAt.AsTime(),
}
}

// FromDocumentSummaries converts the given Protobuf formats to model format.
func FromDocumentSummaries(pbSummaries []*api.DocumentSummary) ([]*types.DocumentSummary, error) {
func FromDocumentSummaries(pbSummaries []*api.DocumentSummary) []*types.DocumentSummary {
var summaries []*types.DocumentSummary
for _, pbSummary := range pbSummaries {
summary, err := FromDocumentSummary(pbSummary)
if err != nil {
return nil, err
}
summaries = append(summaries, summary)
summaries = append(summaries, FromDocumentSummary(pbSummary))
}
return summaries, nil
return summaries
}

// FromDocumentSummary converts the given Protobuf formats to model format.
func FromDocumentSummary(pbSummary *api.DocumentSummary) (*types.DocumentSummary, error) {
createdAt := pbSummary.CreatedAt.AsTime()
accessedAt := pbSummary.AccessedAt.AsTime()
updatedAt := pbSummary.UpdatedAt.AsTime()
func FromDocumentSummary(pbSummary *api.DocumentSummary) *types.DocumentSummary {
return &types.DocumentSummary{
ID: types.ID(pbSummary.Id),
Key: key.Key(pbSummary.Key),
CreatedAt: createdAt,
AccessedAt: accessedAt,
UpdatedAt: updatedAt,
CreatedAt: pbSummary.CreatedAt.AsTime(),
AccessedAt: pbSummary.AccessedAt.AsTime(),
UpdatedAt: pbSummary.UpdatedAt.AsTime(),
Snapshot: pbSummary.Snapshot,
}, nil
}
}

// FromChangePack converts the given Protobuf formats to model format.
Expand Down
6 changes: 2 additions & 4 deletions server/rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,11 @@ func NewServer(conf *Config, be *backend.Backend) (*Server, error) {
newAdminServer(be, tokenManager),
interceptor,
))

checker := grpchealth.NewStaticChecker(
serverMux.Handle(grpchealth.NewHandler(grpchealth.NewStaticChecker(
grpchealth.HealthV1ServiceName,
v1connect.YorkieServiceName,
v1connect.AdminServiceName,
)
serverMux.Handle(grpchealth.NewHandler(checker))
)))

return &Server{
conf: conf,
Expand Down

1 comment on commit c93f27f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go Benchmark

Benchmark suite Current: c93f27f Previous: 3ebef65 Ratio
BenchmarkDocument/constructor_test - ns/op 1329 ns/op 1373 ns/op 0.97
BenchmarkDocument/constructor_test - B/op 1208 B/op 1208 B/op 1
BenchmarkDocument/constructor_test - allocs/op 20 allocs/op 20 allocs/op 1
BenchmarkDocument/status_test - ns/op 787.9 ns/op 796.5 ns/op 0.99
BenchmarkDocument/status_test - B/op 1176 B/op 1176 B/op 1
BenchmarkDocument/status_test - allocs/op 18 allocs/op 18 allocs/op 1
BenchmarkDocument/equals_test - ns/op 7131 ns/op 8302 ns/op 0.86
BenchmarkDocument/equals_test - B/op 6913 B/op 6913 B/op 1
BenchmarkDocument/equals_test - allocs/op 120 allocs/op 120 allocs/op 1
BenchmarkDocument/nested_update_test - ns/op 16094 ns/op 16598 ns/op 0.97
BenchmarkDocument/nested_update_test - B/op 11963 B/op 11962 B/op 1.00
BenchmarkDocument/nested_update_test - allocs/op 254 allocs/op 254 allocs/op 1
BenchmarkDocument/delete_test - ns/op 23831 ns/op 22626 ns/op 1.05
BenchmarkDocument/delete_test - B/op 15188 B/op 15188 B/op 1
BenchmarkDocument/delete_test - allocs/op 333 allocs/op 333 allocs/op 1
BenchmarkDocument/object_test - ns/op 8813 ns/op 8699 ns/op 1.01
BenchmarkDocument/object_test - B/op 6721 B/op 6721 B/op 1
BenchmarkDocument/object_test - allocs/op 116 allocs/op 116 allocs/op 1
BenchmarkDocument/array_test - ns/op 28551 ns/op 29401 ns/op 0.97
BenchmarkDocument/array_test - B/op 11819 B/op 11819 B/op 1
BenchmarkDocument/array_test - allocs/op 270 allocs/op 270 allocs/op 1
BenchmarkDocument/text_test - ns/op 30430 ns/op 31226 ns/op 0.97
BenchmarkDocument/text_test - B/op 14796 B/op 14795 B/op 1.00
BenchmarkDocument/text_test - allocs/op 468 allocs/op 468 allocs/op 1
BenchmarkDocument/text_composition_test - ns/op 28579 ns/op 29299 ns/op 0.98
BenchmarkDocument/text_composition_test - B/op 18278 B/op 18278 B/op 1
BenchmarkDocument/text_composition_test - allocs/op 477 allocs/op 477 allocs/op 1
BenchmarkDocument/rich_text_test - ns/op 80173 ns/op 82820 ns/op 0.97
BenchmarkDocument/rich_text_test - B/op 38540 B/op 38540 B/op 1
BenchmarkDocument/rich_text_test - allocs/op 1147 allocs/op 1147 allocs/op 1
BenchmarkDocument/counter_test - ns/op 16510 ns/op 17386 ns/op 0.95
BenchmarkDocument/counter_test - B/op 10210 B/op 10210 B/op 1
BenchmarkDocument/counter_test - allocs/op 236 allocs/op 236 allocs/op 1
BenchmarkDocument/text_edit_gc_100 - ns/op 2912484 ns/op 2970186 ns/op 0.98
BenchmarkDocument/text_edit_gc_100 - B/op 1655516 B/op 1655326 B/op 1.00
BenchmarkDocument/text_edit_gc_100 - allocs/op 17093 allocs/op 17093 allocs/op 1
BenchmarkDocument/text_edit_gc_1000 - ns/op 232563307 ns/op 231735416 ns/op 1.00
BenchmarkDocument/text_edit_gc_1000 - B/op 144338312 B/op 144366033 B/op 1.00
BenchmarkDocument/text_edit_gc_1000 - allocs/op 200878 allocs/op 201007 allocs/op 1.00
BenchmarkDocument/text_split_gc_100 - ns/op 3402232 ns/op 3385194 ns/op 1.01
BenchmarkDocument/text_split_gc_100 - B/op 2313638 B/op 2313331 B/op 1.00
BenchmarkDocument/text_split_gc_100 - allocs/op 16194 allocs/op 16194 allocs/op 1
BenchmarkDocument/text_split_gc_1000 - ns/op 290561496 ns/op 296761342 ns/op 0.98
BenchmarkDocument/text_split_gc_1000 - B/op 228893424 B/op 228881832 B/op 1.00
BenchmarkDocument/text_split_gc_1000 - allocs/op 203964 allocs/op 203904 allocs/op 1.00
BenchmarkDocument/text_delete_all_10000 - ns/op 11178808 ns/op 11146892 ns/op 1.00
BenchmarkDocument/text_delete_all_10000 - B/op 5809968 B/op 5810543 B/op 1.00
BenchmarkDocument/text_delete_all_10000 - allocs/op 40673 allocs/op 40675 allocs/op 1.00
BenchmarkDocument/text_delete_all_100000 - ns/op 187222551 ns/op 187188955 ns/op 1.00
BenchmarkDocument/text_delete_all_100000 - B/op 81906949 B/op 81887592 B/op 1.00
BenchmarkDocument/text_delete_all_100000 - allocs/op 411656 allocs/op 411550 allocs/op 1.00
BenchmarkDocument/text_100 - ns/op 233272 ns/op 232235 ns/op 1.00
BenchmarkDocument/text_100 - B/op 118484 B/op 118483 B/op 1.00
BenchmarkDocument/text_100 - allocs/op 5080 allocs/op 5080 allocs/op 1
BenchmarkDocument/text_1000 - ns/op 2495717 ns/op 2502773 ns/op 1.00
BenchmarkDocument/text_1000 - B/op 1153071 B/op 1153073 B/op 1.00
BenchmarkDocument/text_1000 - allocs/op 50084 allocs/op 50084 allocs/op 1
BenchmarkDocument/array_1000 - ns/op 1256185 ns/op 1267389 ns/op 0.99
BenchmarkDocument/array_1000 - B/op 1091298 B/op 1091268 B/op 1.00
BenchmarkDocument/array_1000 - allocs/op 11826 allocs/op 11826 allocs/op 1
BenchmarkDocument/array_10000 - ns/op 13152927 ns/op 13549731 ns/op 0.97
BenchmarkDocument/array_10000 - B/op 9799448 B/op 9800047 B/op 1.00
BenchmarkDocument/array_10000 - allocs/op 120289 allocs/op 120291 allocs/op 1.00
BenchmarkDocument/array_gc_100 - ns/op 154167 ns/op 153664 ns/op 1.00
BenchmarkDocument/array_gc_100 - B/op 132485 B/op 132498 B/op 1.00
BenchmarkDocument/array_gc_100 - allocs/op 1248 allocs/op 1248 allocs/op 1
BenchmarkDocument/array_gc_1000 - ns/op 1444176 ns/op 1451255 ns/op 1.00
BenchmarkDocument/array_gc_1000 - B/op 1158831 B/op 1158965 B/op 1.00
BenchmarkDocument/array_gc_1000 - allocs/op 12864 allocs/op 12865 allocs/op 1.00
BenchmarkDocument/counter_1000 - ns/op 211584 ns/op 215664 ns/op 0.98
BenchmarkDocument/counter_1000 - B/op 192850 B/op 192852 B/op 1.00
BenchmarkDocument/counter_1000 - allocs/op 5765 allocs/op 5765 allocs/op 1
BenchmarkDocument/counter_10000 - ns/op 2225345 ns/op 2222359 ns/op 1.00
BenchmarkDocument/counter_10000 - B/op 2087783 B/op 2087783 B/op 1
BenchmarkDocument/counter_10000 - allocs/op 59772 allocs/op 59772 allocs/op 1
BenchmarkDocument/object_1000 - ns/op 1439374 ns/op 1433455 ns/op 1.00
BenchmarkDocument/object_1000 - B/op 1428099 B/op 1427946 B/op 1.00
BenchmarkDocument/object_1000 - allocs/op 9845 allocs/op 9845 allocs/op 1
BenchmarkDocument/object_10000 - ns/op 15165782 ns/op 14878581 ns/op 1.02
BenchmarkDocument/object_10000 - B/op 12166828 B/op 12167003 B/op 1.00
BenchmarkDocument/object_10000 - allocs/op 100562 allocs/op 100561 allocs/op 1.00
BenchmarkDocument/tree_100 - ns/op 1085680 ns/op 722947 ns/op 1.50
BenchmarkDocument/tree_100 - B/op 943678 B/op 442891 B/op 2.13
BenchmarkDocument/tree_100 - allocs/op 6099 allocs/op 4506 allocs/op 1.35
BenchmarkDocument/tree_1000 - ns/op 81913829 ns/op 48715965 ns/op 1.68
BenchmarkDocument/tree_1000 - B/op 86460598 B/op 35222566 B/op 2.45
BenchmarkDocument/tree_1000 - allocs/op 60114 allocs/op 44119 allocs/op 1.36
BenchmarkDocument/tree_10000 - ns/op 10162703235 ns/op 6243742972 ns/op 1.63
BenchmarkDocument/tree_10000 - B/op 8580972024 B/op 3439193776 B/op 2.50
BenchmarkDocument/tree_10000 - allocs/op 600217 allocs/op 440204 allocs/op 1.36
BenchmarkDocument/tree_delete_all_1000 - ns/op 80709211 ns/op 50492483 ns/op 1.60
BenchmarkDocument/tree_delete_all_1000 - B/op 86990174 B/op 35687345 B/op 2.44
BenchmarkDocument/tree_delete_all_1000 - allocs/op 67748 allocs/op 51744 allocs/op 1.31
BenchmarkDocument/tree_edit_gc_100 - ns/op 3943884 ns/op 2674319 ns/op 1.47
BenchmarkDocument/tree_edit_gc_100 - B/op 4121038 B/op 2099522 B/op 1.96
BenchmarkDocument/tree_edit_gc_100 - allocs/op 14356 allocs/op 11165 allocs/op 1.29
BenchmarkDocument/tree_edit_gc_1000 - ns/op 332952566 ns/op 200656697 ns/op 1.66
BenchmarkDocument/tree_edit_gc_1000 - B/op 383468608 B/op 180293307 B/op 2.13
BenchmarkDocument/tree_edit_gc_1000 - allocs/op 145428 allocs/op 113350 allocs/op 1.28
BenchmarkDocument/tree_split_gc_100 - ns/op 2677429 ns/op 1969140 ns/op 1.36
BenchmarkDocument/tree_split_gc_100 - B/op 2386846 B/op 1363475 B/op 1.75
BenchmarkDocument/tree_split_gc_100 - allocs/op 10341 allocs/op 8735 allocs/op 1.18
BenchmarkDocument/tree_split_gc_1000 - ns/op 198498809 ns/op 133034523 ns/op 1.49
BenchmarkDocument/tree_split_gc_1000 - B/op 221992672 B/op 120284053 B/op 1.85
BenchmarkDocument/tree_split_gc_1000 - allocs/op 112270 allocs/op 96193 allocs/op 1.17
BenchmarkRPC/client_to_server - ns/op 360711726 ns/op 356375965 ns/op 1.01
BenchmarkRPC/client_to_server - B/op 17850749 B/op 16323573 B/op 1.09
BenchmarkRPC/client_to_server - allocs/op 166997 allocs/op 165420 allocs/op 1.01
BenchmarkRPC/client_to_client_via_server - ns/op 608900458 ns/op 607723810 ns/op 1.00
BenchmarkRPC/client_to_client_via_server - B/op 35274776 B/op 34041892 B/op 1.04
BenchmarkRPC/client_to_client_via_server - allocs/op 312241 allocs/op 309871 allocs/op 1.01
BenchmarkRPC/attach_large_document - ns/op 1127431187 ns/op 1463602622 ns/op 0.77
BenchmarkRPC/attach_large_document - B/op 1879554984 B/op 1878647264 B/op 1.00
BenchmarkRPC/attach_large_document - allocs/op 7564 allocs/op 7043 allocs/op 1.07
BenchmarkRPC/adminCli_to_server - ns/op 539672634 ns/op 541741676 ns/op 1.00
BenchmarkRPC/adminCli_to_server - B/op 36006592 B/op 36380716 B/op 0.99
BenchmarkRPC/adminCli_to_server - allocs/op 290161 allocs/op 284616 allocs/op 1.02
BenchmarkLocker - ns/op 64.89 ns/op 65.29 ns/op 0.99
BenchmarkLocker - B/op 16 B/op 16 B/op 1
BenchmarkLocker - allocs/op 1 allocs/op 1 allocs/op 1
BenchmarkLockerParallel - ns/op 38.45 ns/op 38.64 ns/op 1.00
BenchmarkLockerParallel - B/op 0 B/op 0 B/op NaN
BenchmarkLockerParallel - allocs/op 0 allocs/op 0 allocs/op NaN
BenchmarkLockerMoreKeys - ns/op 150 ns/op 138.5 ns/op 1.08
BenchmarkLockerMoreKeys - B/op 15 B/op 15 B/op 1
BenchmarkLockerMoreKeys - allocs/op 0 allocs/op 0 allocs/op NaN
BenchmarkChange/Push_10_Changes - ns/op 3798873 ns/op 3779429 ns/op 1.01
BenchmarkChange/Push_10_Changes - B/op 125929 B/op 126275 B/op 1.00
BenchmarkChange/Push_10_Changes - allocs/op 1254 allocs/op 1254 allocs/op 1
BenchmarkChange/Push_100_Changes - ns/op 14240232 ns/op 14129092 ns/op 1.01
BenchmarkChange/Push_100_Changes - B/op 651498 B/op 646942 B/op 1.01
BenchmarkChange/Push_100_Changes - allocs/op 6540 allocs/op 6540 allocs/op 1
BenchmarkChange/Push_1000_Changes - ns/op 114014450 ns/op 113213707 ns/op 1.01
BenchmarkChange/Push_1000_Changes - B/op 6029045 B/op 6011043 B/op 1.00
BenchmarkChange/Push_1000_Changes - allocs/op 62156 allocs/op 62155 allocs/op 1.00
BenchmarkChange/Pull_10_Changes - ns/op 2854561 ns/op 2837624 ns/op 1.01
BenchmarkChange/Pull_10_Changes - B/op 100826 B/op 100327 B/op 1.00
BenchmarkChange/Pull_10_Changes - allocs/op 952 allocs/op 951 allocs/op 1.00
BenchmarkChange/Pull_100_Changes - ns/op 4317586 ns/op 4303014 ns/op 1.00
BenchmarkChange/Pull_100_Changes - B/op 258068 B/op 257269 B/op 1.00
BenchmarkChange/Pull_100_Changes - allocs/op 3154 allocs/op 3154 allocs/op 1
BenchmarkChange/Pull_1000_Changes - ns/op 8339888 ns/op 8473189 ns/op 0.98
BenchmarkChange/Pull_1000_Changes - B/op 1397868 B/op 1393414 B/op 1.00
BenchmarkChange/Pull_1000_Changes - allocs/op 26871 allocs/op 26869 allocs/op 1.00
BenchmarkSnapshot/Push_3KB_snapshot - ns/op 16780124 ns/op 16717315 ns/op 1.00
BenchmarkSnapshot/Push_3KB_snapshot - B/op 805830 B/op 807884 B/op 1.00
BenchmarkSnapshot/Push_3KB_snapshot - allocs/op 6540 allocs/op 6541 allocs/op 1.00
BenchmarkSnapshot/Push_30KB_snapshot - ns/op 117843748 ns/op 117501595 ns/op 1.00
BenchmarkSnapshot/Push_30KB_snapshot - B/op 6307124 B/op 6250940 B/op 1.01
BenchmarkSnapshot/Push_30KB_snapshot - allocs/op 62163 allocs/op 62161 allocs/op 1.00
BenchmarkSnapshot/Pull_3KB_snapshot - ns/op 6552245 ns/op 6521588 ns/op 1.00
BenchmarkSnapshot/Pull_3KB_snapshot - B/op 905499 B/op 904310 B/op 1.00
BenchmarkSnapshot/Pull_3KB_snapshot - allocs/op 14881 allocs/op 14878 allocs/op 1.00
BenchmarkSnapshot/Pull_30KB_snapshot - ns/op 14666992 ns/op 15228711 ns/op 0.96
BenchmarkSnapshot/Pull_30KB_snapshot - B/op 6984670 B/op 6983077 B/op 1.00
BenchmarkSnapshot/Pull_30KB_snapshot - allocs/op 144113 allocs/op 144141 allocs/op 1.00
BenchmarkSync/memory_sync_10_test - ns/op 6802 ns/op 6917 ns/op 0.98
BenchmarkSync/memory_sync_10_test - B/op 1286 B/op 1286 B/op 1
BenchmarkSync/memory_sync_10_test - allocs/op 38 allocs/op 38 allocs/op 1
BenchmarkSync/memory_sync_100_test - ns/op 51952 ns/op 51493 ns/op 1.01
BenchmarkSync/memory_sync_100_test - B/op 8647 B/op 8650 B/op 1.00
BenchmarkSync/memory_sync_100_test - allocs/op 273 allocs/op 273 allocs/op 1
BenchmarkSync/memory_sync_1000_test - ns/op 588952 ns/op 598451 ns/op 0.98
BenchmarkSync/memory_sync_1000_test - B/op 74922 B/op 74330 B/op 1.01
BenchmarkSync/memory_sync_1000_test - allocs/op 2145 allocs/op 2108 allocs/op 1.02
BenchmarkSync/memory_sync_10000_test - ns/op 7773821 ns/op 7141413 ns/op 1.09
BenchmarkSync/memory_sync_10000_test - B/op 758360 B/op 761330 B/op 1.00
BenchmarkSync/memory_sync_10000_test - allocs/op 20460 allocs/op 20560 allocs/op 1.00
BenchmarkTextEditing - ns/op 19309791441 ns/op 19117165431 ns/op 1.01
BenchmarkTextEditing - B/op 9038138688 B/op 9037584392 B/op 1.00
BenchmarkTextEditing - allocs/op 19924090 allocs/op 19921383 allocs/op 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.