-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor PastIteration mounting process
It was full of N+1 queries, and getting the things very slow
- Loading branch information
1 parent
d58c745
commit 2f2a0a6
Showing
5 changed files
with
81 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,15 @@ | ||
module Iterations | ||
class PastIteration | ||
attr_reader :start_date, :end_date, :points, :iteration_number | ||
include Virtus.model | ||
|
||
def initialize(start_date:, end_date:, project:, iteration_number: nil) | ||
@start_date = start_date | ||
@end_date = end_date | ||
@project = project | ||
@points = points | ||
@iteration_number = iteration_number | ||
end | ||
attribute :start_date, DateTime | ||
attribute :end_date, DateTime | ||
attribute :iteration_number, Integer | ||
attribute :stories, Array[Story] | ||
attribute :points, Integer | ||
|
||
def points | ||
@points ||= stories.sum(:estimate) | ||
end | ||
|
||
def stories | ||
@stories ||= @project.stories.where( | ||
'accepted_at >= ? AND accepted_at <= ?', @start_date, @end_date | ||
) | ||
@points ||= stories.to_a.map(&:estimate).compact.sum | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters