Bnei-Baruch/mdb

View on GitHub
batch/convert.go

Summary

Maintainability
C
7 hrs
Test Coverage

Function populateDBQueue has a Cognitive Complexity of 36 (exceeds 20 allowed). Consider refactoring.
Open

func populateDBQueue(files []*models.File) error {
    cuMap := make(map[int64]map[string][]*models.File)
    noCU := make([]*models.File, 0)
    withChilds := make(map[int64]bool)
    var ok bool
Severity: Minor
Found in batch/convert.go - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function populateDBQueue has 89 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func populateDBQueue(files []*models.File) error {
    cuMap := make(map[int64]map[string][]*models.File)
    noCU := make([]*models.File, 0)
    withChilds := make(map[int64]bool)
    var ok bool
Severity: Major
Found in batch/convert.go - About 2 hrs to fix

    Function fillQueue has 7 return statements (exceeds 4 allowed).
    Open

    func fillQueue(files []*models.File) error {
        tx, err := mdb.Begin()
        if err != nil {
            return errors.Wrap(err, "Begin transaction")
        }
    Severity: Major
    Found in batch/convert.go - About 45 mins to fix

      Function doQueueWork has 6 return statements (exceeds 4 allowed).
      Open

      func doQueueWork() error {
          // clear previously rejected files
          _, err := queries.Raw(
              "update batch_convert set request_at = null, request_error = null where request_error=$1",
              "Cannot start transcoding").Exec(mdb)
      Severity: Major
      Found in batch/convert.go - About 40 mins to fix

        Function queueFile has 5 return statements (exceeds 4 allowed).
        Open

        func queueFile(id int64, sha1 string) error {
            url := "http://files.kabbalahmedia.info/api/v1/transcode"
        
            resp, err := utils.HttpPostJson(url, TranscodeRequest{Sha1: sha1, Format: "mp4"})
            if err != nil {
        Severity: Major
        Found in batch/convert.go - About 35 mins to fix

          There are no issues that match your filters.

          Category
          Status