Skip to content

Commit

Permalink
feat: BED-5079 - add a count function for efficiently counting ingest…
Browse files Browse the repository at this point in the history
… tasks
  • Loading branch information
zinic committed Nov 27, 2024
1 parent cf854b2 commit 6b9c6c0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/api/src/api/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const (
ErrorResponseDetailsOTPInvalid = "one time password is invalid"
ErrorResponseDetailsResourceNotFound = "resource not found"
ErrorResponseDetailsToBeforeFrom = "to time cannot be before from time"
ErrorResponseDetailsTimeRangeInvalid = "time range provided is invalid"
ErrorResponseDetailsTimeRangeInvalid = "time range provided is invalid"
ErrorResponseDetailsToMalformed = "to parameter should be formatted as RFC3339 i.e 2021-04-21T07:20:50.52Z"
ErrorResponseMultipleCollectionScopesProvided = "may only scope collection by exactly one of OU, Domain, or All Trusted Domains"
ErrorResponsePayloadUnmarshalError = "error unmarshalling JSON payload"
Expand Down
1 change: 1 addition & 0 deletions cmd/api/src/database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type Database interface {
// Ingest
ingest.IngestData
GetAllIngestTasks(ctx context.Context) (model.IngestTasks, error)
CountAllIngestTasks(ctx context.Context) (int64, error)
DeleteIngestTask(ctx context.Context, ingestTask model.IngestTask) error
GetIngestTasksForJob(ctx context.Context, jobID int64) (model.IngestTasks, error)

Expand Down
10 changes: 10 additions & 0 deletions cmd/api/src/database/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ func (s *BloodhoundDB) GetAllIngestTasks(ctx context.Context) (model.IngestTasks
return ingestTasks, CheckError(result)
}

func (s *BloodhoundDB) CountAllIngestTasks(ctx context.Context) (int64, error) {
var (
ingestTaskCount int64
ingestTasksModel model.IngestTasks
)

result := s.db.Model(&ingestTasksModel).WithContext(ctx).Count(&ingestTaskCount)
return ingestTaskCount, CheckError(result)
}

func (s *BloodhoundDB) DeleteIngestTask(ctx context.Context, ingestTask model.IngestTask) error {
result := s.db.WithContext(ctx).Delete(&ingestTask)
return CheckError(result)
Expand Down
15 changes: 15 additions & 0 deletions cmd/api/src/database/mocks/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6b9c6c0

Please sign in to comment.