package handlers import "apjournal/internal/models" func (h *Handlers) fetchRecommendations( username string, limit int, ) ([]models.Action, error) { actionsRes := []models.Action{} acts, err := h.repo.DBActionRecommend(username) if err != nil { return nil, err } plusCounter := 0 minusCounter := 0 for _, act := range acts { if act.Type == models.ActionTypePlus { if plusCounter >= limit { continue } actionsRes = append(actionsRes, act) plusCounter++ continue } if minusCounter >= limit { continue } actionsRes = append(actionsRes, act) minusCounter++ if len(actionsRes) > limit*2 { break } } h.log.Debug("actions rec debug", "db_acts#", len(acts), "res_acts#", len(actionsRes)) return actionsRes, nil }