glitch-soc/mastodon

View on GitHub
app/lib/feed_manager.rb

Summary

Maintainability
D
3 days
Test Coverage

File feed_manager.rb has 346 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'singleton'

class FeedManager
  include Singleton
  include Redisable
Severity: Minor
Found in app/lib/feed_manager.rb - About 4 hrs to fix

    Class FeedManager has 32 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class FeedManager
      include Singleton
      include Redisable
    
      # Maximum number of items stored in a single feed
    Severity: Minor
    Found in app/lib/feed_manager.rb - About 4 hrs to fix

      Method filter_from_home? has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

        def filter_from_home?(status, receiver_id, crutches, timeline_type = :home)
          return false if receiver_id == status.account_id
          return true  if status.reply? && (status.in_reply_to_id.nil? || status.in_reply_to_account_id.nil?)
          return true if timeline_type != :list && crutches[:exclusive_list_users][status.account_id].present?
          return true if crutches[:languages][status.account_id].present? && status.language.present? && !crutches[:languages][status.account_id].include?(status.language)
      Severity: Minor
      Found in app/lib/feed_manager.rb - 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

      Method populate_direct_feed has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

        def populate_direct_feed(account)
          added  = 0
          limit  = FeedManager::MAX_ITEMS / 2
          max_id = nil
      
      
      Severity: Minor
      Found in app/lib/feed_manager.rb - 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

      Method add_to_feed has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def add_to_feed(timeline_type, account_id, status, aggregate_reblogs: true)
          timeline_key = key(timeline_type, account_id)
          reblog_key   = key(timeline_type, account_id, 'reblogs')
      
          if status.reblog? && (aggregate_reblogs.nil? || aggregate_reblogs)
      Severity: Minor
      Found in app/lib/feed_manager.rb - 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

      Method populate_home has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

        def populate_home(account)
          limit        = FeedManager::MAX_ITEMS / 2
          aggregate    = account.user&.aggregates_reblogs?
          timeline_key = key(:home, account.id)
      
      
      Severity: Minor
      Found in app/lib/feed_manager.rb - 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

      Method remove_from_feed has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

        def remove_from_feed(timeline_type, account_id, status, aggregate_reblogs: true)
          timeline_key = key(timeline_type, account_id)
          reblog_key   = key(timeline_type, account_id, 'reblogs')
      
          if status.reblog? && (aggregate_reblogs.nil? || aggregate_reblogs)
      Severity: Minor
      Found in app/lib/feed_manager.rb - 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

      Method build_crutches has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def build_crutches(receiver_id, statuses)
          crutches = {}
      
          crutches[:active_mentions] = crutches_active_mentions(statuses)
      
      
      Severity: Minor
      Found in app/lib/feed_manager.rb - About 35 mins 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 method.
      Open

          return true if check_for_blocks.any? { |target_account_id| crutches[:blocking][target_account_id] || crutches[:muting][target_account_id] }
      Severity: Major
      Found in app/lib/feed_manager.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

              return !!should_filter
        Severity: Major
        Found in app/lib/feed_manager.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

              return true if crutches[:blocked_by][status.account_id]
          Severity: Major
          Found in app/lib/feed_manager.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                  return !!should_filter
            Severity: Major
            Found in app/lib/feed_manager.rb - About 30 mins to fix

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

                def clear_from_list(list, target_account)
                  timeline_key        = key(:list, list.id)
                  timeline_status_ids = redis.zrange(timeline_key, 0, -1)
                  statuses            = Status.where(id: timeline_status_ids).select(:id, :reblog_of_id, :account_id).to_a
                  reblogged_ids       = Status.where(id: statuses.filter_map(&:reblog_of_id), account: target_account).pluck(:id)
              Severity: Major
              Found in app/lib/feed_manager.rb and 1 other location - About 2 hrs to fix
              app/lib/feed_manager.rb on lines 233..245

              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 89.

              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

                def clear_from_home(account, target_account)
                  timeline_key        = key(:home, account.id)
                  timeline_status_ids = redis.zrange(timeline_key, 0, -1)
                  statuses            = Status.where(id: timeline_status_ids).select(:id, :reblog_of_id, :account_id).to_a
                  reblogged_ids       = Status.where(id: statuses.filter_map(&:reblog_of_id), account: target_account).pluck(:id)
              Severity: Major
              Found in app/lib/feed_manager.rb and 1 other location - About 2 hrs to fix
              app/lib/feed_manager.rb on lines 253..265

              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 89.

              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

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

                  if redis.zcard(timeline_key) >= FeedManager::MAX_ITEMS / 4
                    oldest_home_score = redis.zrange(timeline_key, 0, 0, with_scores: true).first.last.to_i
                    query = query.where('id > ?', oldest_home_score)
              Severity: Minor
              Found in app/lib/feed_manager.rb and 1 other location - About 20 mins to fix
              app/lib/feed_manager.rb on lines 139..141

              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 27.

              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

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

                  if redis.zcard(timeline_key) >= FeedManager::MAX_ITEMS / 4
                    oldest_home_score = redis.zrange(timeline_key, 0, 0, with_scores: true).first.last.to_i
                    query = query.where('id > ?', oldest_home_score)
              Severity: Minor
              Found in app/lib/feed_manager.rb and 1 other location - About 20 mins to fix
              app/lib/feed_manager.rb on lines 165..167

              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 27.

              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