duplicate processing

This commit is contained in:
pasha1coil 2023-11-23 00:30:59 +03:00 committed by skeris
parent ae5e06be33
commit 1231ee9aaa

@ -116,6 +116,7 @@ func (receiver *HistoryRepository) GetRecentTariffs(ctx context.Context, userID
var result []struct {
ID string `bson:"tariffID"`
}
filter := bson.D{
{Key: fields.History.UserID, Value: userID},
{Key: fields.History.IsDeleted, Value: false},
@ -146,9 +147,13 @@ func (receiver *HistoryRepository) GetRecentTariffs(ctx context.Context, userID
errors.ErrInternalError,
)
}
tariffs := make([]string, len(result))
for i, item := range result {
tariffs[i] = item.ID
tariffSet := make(map[string]struct{}, len(result))
for _, item := range result {
tariffSet[item.ID] = struct{}{}
}
tariffs := make([]string, 0, len(tariffSet))
for tariff := range tariffSet {
tariffs = append(tariffs, tariff)
}
return tariffs, nil
}