mashirozx/mastodon

View on GitHub
app/lib/feed_manager.rb

Summary

Maintainability
D
2 days
Test Coverage

Class FeedManager has 26 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 3 hrs to fix

    File feed_manager.rb has 289 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 2 hrs to fix

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

        def filter_from_home?(status, receiver_id, crutches)
          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?)
      
          check_for_blocks = crutches[:active_mentions][status.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 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 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 populate_home has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

        def populate_home(account)
          limit        = FeedManager::MAX_ITEMS / 2
          aggregate    = true
          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

      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

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

          def build_crutches(receiver_id, statuses)
            crutches = {}
        
            crutches[:active_mentions] = Mention.active.where(status_id: statuses.flat_map { |s| [s.id, s.reblog_of_id] }.compact).pluck(:status_id, :account_id).each_with_object({}) { |(id, account_id), mapping| (mapping[id] ||= []).push(account_id) }
        
        
        Severity: Minor
        Found in app/lib/feed_manager.rb - About 25 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

        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.map(&:reblog_of_id).compact, 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 207..219

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

        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_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.map(&:reblog_of_id).compact, 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 187..199

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

        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 unmerge_from_home(from_account, into_account)
            timeline_key        = key(:home, into_account.id)
            timeline_status_ids = redis.zrange(timeline_key, 0, -1)
        
            from_account.statuses.select('id, reblog_of_id').where(id: timeline_status_ids).reorder(nil).find_each do |status|
        Severity: Minor
        Found in app/lib/feed_manager.rb and 1 other location - About 35 mins to fix
        app/lib/feed_manager.rb on lines 174..179

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

        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 unmerge_from_list(from_account, list)
            timeline_key        = key(:list, list.id)
            timeline_status_ids = redis.zrange(timeline_key, 0, -1)
        
            from_account.statuses.select('id, reblog_of_id').where(id: timeline_status_ids).reorder(nil).find_each do |status|
        Severity: Minor
        Found in app/lib/feed_manager.rb and 1 other location - About 35 mins to fix
        app/lib/feed_manager.rb on lines 161..166

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

        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 unpush_from_home(account, status, update: false)
            return false unless remove_from_feed(:home, account.id, status, aggregate_reblogs: true)
        
            redis.publish("timeline:#{account.id}", Oj.dump(event: :delete, payload: status.id.to_s)) unless update
            true
        Severity: Minor
        Found in app/lib/feed_manager.rb and 1 other location - About 30 mins to fix
        app/lib/feed_manager.rb on lines 98..102

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

        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 unpush_from_list(list, status, update: false)
            return false unless remove_from_feed(:list, list.id, status, aggregate_reblogs: true)
        
            redis.publish("timeline:list:#{list.id}", Oj.dump(event: :delete, payload: status.id.to_s)) unless update
            true
        Severity: Minor
        Found in app/lib/feed_manager.rb and 1 other location - About 30 mins to fix
        app/lib/feed_manager.rb on lines 73..77

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

        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 114..116

        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 140..142

        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