• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / deployments / 1376315855

04 Jul 2024 10:22AM UTC coverage: 79.694% (-0.06%) from 79.752%
1376315855

push

gitlab-ci

web-flow
Merge pull request #1029 from alfrunes/perf-deployment-status

perf: Optimize database interactions when updating deployment stats

59 of 80 new or added lines in 3 files covered. (73.75%)

711 existing lines in 10 files now uncovered.

8124 of 10194 relevant lines covered (79.69%)

34.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/app/app_last_status.go
1
// Copyright 2023 Northern.tech AS
2
//
3
//        Licensed under the Apache License, Version 2.0 (the "License");
4
//        you may not use this file except in compliance with the License.
5
//        You may obtain a copy of the License at
6
//
7
//            http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//        Unless required by applicable law or agreed to in writing, software
10
//        distributed under the License is distributed on an "AS IS" BASIS,
11
//        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//        See the License for the specific language governing permissions and
13
//        limitations under the License.
14

15
package app
16

17
import (
18
        "context"
19

20
        "github.com/pkg/errors"
21

22
        "github.com/mendersoftware/deployments/model"
23
)
24

25
const (
26
        MaxDeviceArrayLength = 1024
27
)
28

29
var (
30
        ErrNoIdsGiven  = errors.New("need at least one device id")
31
        ErrArrayTooBig = errors.New("too many device ids given")
32
)
33

34
// GetDeviceDeploymentLastStatus returns the array of last device deployment statuses.
35
func (d *Deployments) GetDeviceDeploymentLastStatus(
36
        ctx context.Context,
37
        devicesIds []string,
38
) (model.DeviceDeploymentLastStatuses, error) {
4✔
39
        length := len(devicesIds)
4✔
40
        if length < 1 {
5✔
41
                return model.DeviceDeploymentLastStatuses{
1✔
42
                        DeviceDeploymentLastStatuses: []model.DeviceDeploymentLastStatus{},
1✔
43
                }, ErrNoIdsGiven
1✔
44
        }
1✔
45
        if length > MaxDeviceArrayLength {
4✔
46
                return model.DeviceDeploymentLastStatuses{
1✔
47
                        DeviceDeploymentLastStatuses: []model.DeviceDeploymentLastStatus{},
1✔
48
                }, ErrArrayTooBig
1✔
49
        }
1✔
50

51
        statuses, err := d.db.GetLastDeviceDeploymentStatus(ctx, devicesIds)
2✔
52
        if len(statuses) < 1 {
3✔
UNCOV
53
                statuses = []model.DeviceDeploymentLastStatus{}
1✔
UNCOV
54
        }
1✔
55
        return model.DeviceDeploymentLastStatuses{
2✔
56
                DeviceDeploymentLastStatuses: statuses,
2✔
57
        }, err
2✔
58
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc