|
1 | 1 | include ApplicationHelper
|
2 | 2 |
|
3 | 3 | class WakatimeService
|
4 |
| - def initialize(user: nil, specific_filters: [], allow_cache: true, limit: 10, start_date: nil, end_date: nil, scope: nil, boundary_aware: false) |
| 4 | + def initialize(user: nil, specific_filters: [], allow_cache: true, limit: 10, start_date: nil, end_date: nil, scope: nil) |
5 | 5 | @scope = scope || Heartbeat.all
|
6 | 6 | @user = user
|
7 |
| - @boundary_aware = boundary_aware |
8 | 7 |
|
9 | 8 | @start_date = convert_to_unix_timestamp(start_date)
|
10 | 9 | @end_date = convert_to_unix_timestamp(end_date)
|
11 | 10 |
|
12 |
| - # apply with_valid_timestamps filter if no custom scope provided-- this is copied from query in stats_controller |
13 |
| - if scope.nil? |
14 |
| - @scope = @scope.with_valid_timestamps |
15 |
| - end |
16 |
| - |
17 | 11 | # Default to 1 year ago if no start_date provided or if no data exists
|
18 | 12 | @start_date = @start_date || @scope.minimum(:time) || 1.year.ago.to_i
|
19 | 13 | @end_date = @end_date || @scope.maximum(:time) || Time.current.to_i
|
20 | 14 |
|
21 |
| - @scope = @scope.where(time: @start_date..@end_date) |
| 15 | + @scope = @scope.where("time >= ? AND time < ?", @start_date, @end_date) |
22 | 16 |
|
23 | 17 | @limit = limit
|
24 | 18 | @limit = nil if @limit&.zero?
|
@@ -47,14 +41,7 @@ def generate_summary
|
47 | 41 | summary[:range] = "all_time"
|
48 | 42 | summary[:human_readable_range] = "All Time"
|
49 | 43 |
|
50 |
| - @total_seconds = if @boundary_aware |
51 |
| - result = Heartbeat.duration_seconds_boundary_aware(@scope, @start_date, @end_date) || 0 |
52 |
| - result |
53 |
| - else |
54 |
| - result = @scope.duration_seconds || 0 |
55 |
| - result |
56 |
| - end |
57 |
| - |
| 44 | + @total_seconds = @scope.duration_seconds || 0 |
58 | 45 | summary[:total_seconds] = @total_seconds
|
59 | 46 |
|
60 | 47 | @total_days = (@end_time - @start_time) / 86400
|
|
0 commit comments