Use capacity to avoid arr copying #noissue

This commit is contained in:
Varakh 2024-06-02 23:13:44 +02:00
parent d958f48717
commit 302d0b1ad4
10 changed files with 16 additions and 15 deletions

View file

@ -29,7 +29,7 @@ func (h *actionHandler) paginate(c *gin.Context) {
} }
var data []*api.ActionResponse var data []*api.ActionResponse
data = make([]*api.ActionResponse, 0) data = make([]*api.ActionResponse, 0, len(actions))
for _, e := range actions { for _, e := range actions {
data = append(data, &api.ActionResponse{ data = append(data, &api.ActionResponse{

View file

@ -56,7 +56,7 @@ func (h *actionInvocationHandler) paginate(c *gin.Context) {
} }
var data []*api.ActionInvocationResponse var data []*api.ActionInvocationResponse
data = make([]*api.ActionInvocationResponse, 0) data = make([]*api.ActionInvocationResponse, 0, len(actionInvocations))
for _, e := range actionInvocations { for _, e := range actionInvocations {
data = append(data, &api.ActionInvocationResponse{ data = append(data, &api.ActionInvocationResponse{

View file

@ -29,7 +29,7 @@ func (h *eventHandler) window(c *gin.Context) {
} }
var data []*api.EventResponse var data []*api.EventResponse
data = make([]*api.EventResponse, 0) data = make([]*api.EventResponse, 0, len(events))
for _, e := range events { for _, e := range events {
data = append(data, &api.EventResponse{ data = append(data, &api.EventResponse{

View file

@ -24,7 +24,7 @@ func (h *secretHandler) getAll(c *gin.Context) {
} }
var data []*api.SecretResponse var data []*api.SecretResponse
data = make([]*api.SecretResponse, 0) data = make([]*api.SecretResponse, 0, len(secrets))
for _, e := range secrets { for _, e := range secrets {
data = append(data, &api.SecretResponse{ data = append(data, &api.SecretResponse{

View file

@ -28,7 +28,7 @@ func (h *updateHandler) paginate(c *gin.Context) {
s, stateQueryContainsAtLeastOne := c.GetQueryArray("state") s, stateQueryContainsAtLeastOne := c.GetQueryArray("state")
var states []api.UpdateState states := make([]api.UpdateState, 0)
if stateQueryContainsAtLeastOne { if stateQueryContainsAtLeastOne {
for _, state := range s { for _, state := range s {
states = append(states, api.UpdateState(state)) states = append(states, api.UpdateState(state))

View file

@ -29,7 +29,7 @@ func (h *webhookHandler) paginate(c *gin.Context) {
} }
var data []*api.WebhookResponse var data []*api.WebhookResponse
data = make([]*api.WebhookResponse, 0) data = make([]*api.WebhookResponse, 0, len(webhooks))
for _, e := range webhooks { for _, e := range webhooks {
data = append(data, &api.WebhookResponse{ data = append(data, &api.WebhookResponse{

View file

@ -225,8 +225,8 @@ func (r *actionInvocationDbRepo) deleteByUpdatedAtBeforeAndStates(time time.Time
} }
func translateActionInvocationState(state ...api.ActionInvocationState) []string { func translateActionInvocationState(state ...api.ActionInvocationState) []string {
states := make([]string, 0) states := make([]string, 0, len(state))
if len(state) > 0 { if len(states) > 0 {
for _, s := range state { for _, s := range state {
states = append(states, s.Value()) states = append(states, s.Value())
} }

View file

@ -125,7 +125,7 @@ func (r *eventDbRepo) deleteByUpdatedAtBeforeAndStates(time time.Time, state ...
return 0, errorValidationNotEmpty return 0, errorValidationNotEmpty
} }
states := make([]string, 0) states := make([]string, 0, len(state))
for _, i := range state { for _, i := range state {
states = append(states, i.Value()) states = append(states, i.Value())
} }

View file

@ -199,7 +199,7 @@ func (r *updateDbRepo) deleteByUpdatedAtBeforeAndStates(time time.Time, state ..
return 0, errorValidationNotEmpty return 0, errorValidationNotEmpty
} }
states := make([]string, 0) states := make([]string, 0, len(state))
for _, i := range state { for _, i := range state {
states = append(states, i.Value()) states = append(states, i.Value())
} }
@ -231,8 +231,8 @@ func (r *updateDbRepo) paginate(page int, pageSize int, orderBy string, order st
order = "desc" order = "desc"
} }
states := make([]string, 0) states := make([]string, 0, len(state))
if len(state) > 0 { if len(states) > 0 {
for _, s := range state { for _, s := range state {
states = append(states, s.Value()) states = append(states, s.Value())
} }
@ -248,8 +248,8 @@ func (r *updateDbRepo) paginate(page int, pageSize int, orderBy string, order st
func (r *updateDbRepo) count(searchTerm string, searchIn string, state ...api.UpdateState) (int64, error) { func (r *updateDbRepo) count(searchTerm string, searchIn string, state ...api.UpdateState) (int64, error) {
var c int64 var c int64
states := make([]string, 0) states := make([]string, 0, len(state))
if len(state) > 0 { if len(states) > 0 {
for _, s := range state { for _, s := range state {
states = append(states, s.Value()) states = append(states, s.Value())
} }

View file

@ -65,7 +65,8 @@ func (s *actionInvocationService) enqueueFromEvent(event *Event, actions []*Acti
return err return err
} }
var filteredActions []*Action filteredActions := make([]*Action, 0)
for _, action := range actions { for _, action := range actions {
matchesEvent := action.MatchEvent == nil || *action.MatchEvent == event.Name matchesEvent := action.MatchEvent == nil || *action.MatchEvent == event.Name
matchesHost := action.MatchHost == nil || *action.MatchHost == eventPayload.Host matchesHost := action.MatchHost == nil || *action.MatchHost == eventPayload.Host