bcgov/common-object-management-service

View on GitHub
app/src/services/sync.js

Summary

Maintainability
F
1 wk
Test Coverage
A
95%

Function syncVersions has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
Open

  syncVersions: async (object, userId = SYSTEM_USER, etrx = undefined) => {
    let trx;
    try {
      trx = etrx ? etrx : await Version.startTransaction();

Severity: Minor
Found in app/src/services/sync.js - About 1 day 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 syncVersions has 109 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  syncVersions: async (object, userId = SYSTEM_USER, etrx = undefined) => {
    let trx;
    try {
      trx = etrx ? etrx : await Version.startTransaction();

Severity: Major
Found in app/src/services/sync.js - About 4 hrs to fix

    File sync.js has 343 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    const { NIL: SYSTEM_USER, v4: uuidv4, validate: uuidValidate } = require('uuid');
    
    const log = require('../components/log')(module.filename);
    const utils = require('../db/models/utils');
    
    
    Severity: Minor
    Found in app/src/services/sync.js - About 4 hrs to fix

      Function syncTags has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

        syncTags: async (version, path, bucketId = undefined, userId = SYSTEM_USER, etrx = undefined) => {
          let trx;
          try {
            trx = etrx ? etrx : await Version.startTransaction();
            let response = [];
      Severity: Minor
      Found in app/src/services/sync.js - About 3 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 response has 76 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            const response = await Promise.all(s3Versions.map(async s3Version => {
              // S3 Object is in non-versioned bucket
              if (s3Version.VersionId === 'null') {
                const mimeType = await storageService.headObject({
                  filePath: comsObject.path,
      Severity: Major
      Found in app/src/services/sync.js - About 3 hrs to fix

        Function syncObject has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

          syncObject: async (path, bucketId, userId = SYSTEM_USER, etrx = undefined) => {
            let trx;
            try {
              trx = etrx ? etrx : await ObjectModel.startTransaction();
        
        
        Severity: Minor
        Found in app/src/services/sync.js - 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 syncMetadata has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

          syncMetadata: async (version, path, bucketId = undefined, userId = SYSTEM_USER, etrx = undefined) => {
            let trx;
            try {
              trx = etrx ? etrx : await Version.startTransaction();
              let response = [];
        Severity: Minor
        Found in app/src/services/sync.js - 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 syncObject has 57 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          syncObject: async (path, bucketId, userId = SYSTEM_USER, etrx = undefined) => {
            let trx;
            try {
              trx = etrx ? etrx : await ObjectModel.startTransaction();
        
        
        Severity: Major
        Found in app/src/services/sync.js - About 2 hrs to fix

          Function syncTags has 54 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            syncTags: async (version, path, bucketId = undefined, userId = SYSTEM_USER, etrx = undefined) => {
              let trx;
              try {
                trx = etrx ? etrx : await Version.startTransaction();
                let response = [];
          Severity: Major
          Found in app/src/services/sync.js - About 2 hrs to fix

            Function _deriveObjectId has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

              _deriveObjectId: async (s3Object, path, bucketId) => {
                let objId = uuidv4();
            
                if (typeof s3Object === 'object') { // If regular S3 Object
                  const TagSet = await storageService.getObjectTagging({ filePath: path, bucketId: bucketId })
            Severity: Minor
            Found in app/src/services/sync.js - About 1 hr 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 syncMetadata has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              syncMetadata: async (version, path, bucketId = undefined, userId = SYSTEM_USER, etrx = undefined) => {
                let trx;
                try {
                  trx = etrx ? etrx : await Version.startTransaction();
                  let response = [];
            Severity: Minor
            Found in app/src/services/sync.js - About 1 hr to fix

              Function _deriveObjectId has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                _deriveObjectId: async (s3Object, path, bucketId) => {
                  let objId = uuidv4();
              
                  if (typeof s3Object === 'object') { // If regular S3 Object
                    const TagSet = await storageService.getObjectTagging({ filePath: path, bucketId: bucketId })
              Severity: Minor
              Found in app/src/services/sync.js - About 1 hr to fix

                Function syncJob has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                  syncJob: async (path, bucketId, full = false, userId = SYSTEM_USER) => {
                    try {
                      if (!path) throw new Error('Path must be defined');
                
                      return await utils.trxWrapper(async (trx) => {
                Severity: Minor
                Found in app/src/services/sync.js - About 1 hr 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

                Avoid too many return statements within this function.
                Open

                            return { modified: true, version: newVersion };
                Severity: Major
                Found in app/src/services/sync.js - About 30 mins to fix

                  TODO found
                  Open

                            // TODO: Relatively slow operations - determine if this can be optimized
                  Severity: Minor
                  Found in app/src/services/sync.js by fixme

                  TODO found
                  Open

                         * TODO: check if this version is still also the latest on corresponding version in S3
                  Severity: Minor
                  Found in app/src/services/sync.js by fixme

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                        const [comsTagsForVersion, s3TagsForVersion] = await Promise.allSettled([
                          tagService.fetchTagsForVersion({ versionIds: comsVersion.id }, trx),
                          storageService.getObjectTagging({ filePath: path, s3VersionId: comsVersion.s3VersionId, bucketId: bucketId })
                        ]).then(settled => settled.map(promise => promise.value));
                  Severity: Major
                  Found in app/src/services/sync.js and 1 other location - About 3 hrs to fix
                  app/src/services/sync.js on lines 487..490

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 102.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                        const [comsMetadataForVersion, s3ObjectHead] = await Promise.allSettled([
                          metadataService.fetchMetadataForVersion({ versionIds: comsVersion.id }, trx),
                          storageService.headObject({ filePath: path, s3VersionId: comsVersion.s3VersionId, bucketId: bucketId })
                        ]).then(settled => settled.map(promise => promise.value));
                  Severity: Major
                  Found in app/src/services/sync.js and 1 other location - About 3 hrs to fix
                  app/src/services/sync.js on lines 393..396

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 102.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                        for (const s3Tag of s3Tags) {
                          if (!comsTags.some(comsT => comsT.key === s3Tag.key && comsT.value === s3Tag.value)) {
                            newTags.push(s3Tag);
                          } else {
                            response.push(s3Tag);
                  Severity: Major
                  Found in app/src/services/sync.js and 1 other location - About 2 hrs to fix
                  app/src/services/sync.js on lines 510..516

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 88.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                        for (const s3M of s3Metadata) {
                          if (!comsMetadata.some(comsM => comsM.key === s3M.key && comsM.value === s3M.value)) {
                            newMetadata.push(s3M);
                          } else {
                            response.push(s3M);
                  Severity: Major
                  Found in app/src/services/sync.js and 1 other location - About 2 hrs to fix
                  app/src/services/sync.js on lines 443..449

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 88.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                        for (const comsM of comsMetadata) {
                          if (!s3Metadata.some(s3M => s3M.key === comsM.key && s3M.value === comsM.value)) {
                            oldMetadata.push(comsM);
                          }
                        }
                  Severity: Major
                  Found in app/src/services/sync.js and 1 other location - About 1 hr to fix
                  app/src/services/sync.js on lines 432..436

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 73.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                        for (const comsT of comsTags) {
                          if (!s3Tags.some(s3T => s3T.key === comsT.key && s3T.value === comsT.value)) {
                            oldTags.push(comsT);
                          }
                        }
                  Severity: Major
                  Found in app/src/services/sync.js and 1 other location - About 1 hr to fix
                  app/src/services/sync.js on lines 499..503

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 73.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                        if (newTags.length > 0) {
                          await tagService.associateTags(comsVersion.id, newTags, userId, trx);
                          response.push(...newTags);
                        }
                  Severity: Minor
                  Found in app/src/services/sync.js and 1 other location - About 40 mins to fix
                  app/src/services/sync.js on lines 517..520

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 48.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                        if (newMetadata.length > 0) {
                          await metadataService.associateMetadata(version.id, newMetadata, userId, trx);
                          response.push(...newMetadata);
                        }
                  Severity: Minor
                  Found in app/src/services/sync.js and 1 other location - About 40 mins to fix
                  app/src/services/sync.js on lines 450..453

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 48.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  There are no issues that match your filters.

                  Category
                  Status