Skip to content

Commit

Permalink
add include_revisions param to content_followed_in_period (publiclab#…
Browse files Browse the repository at this point in the history
…5907)

* testing tests

* Update comment_test.rb

* add include_revisions param to content_followed_in_period

Fixes publiclab#4732
  • Loading branch information
jywarren authored and enviro3 committed Aug 12, 2019
1 parent 20ac6d9 commit 03ccee1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,22 @@ def questions
Node.questions.where(status: 1, uid: id)
end

def content_followed_in_period(start_time, end_time, node_type = 'note')
def content_followed_in_period(start_time, end_time, node_type = 'note', include_revisions = false)
tagnames = TagSelection.where(following: true, user_id: uid)
node_ids = []
tagnames.each do |tagname|
node_ids += NodeTag.where(tid: tagname.tid).collect(&:nid)
end

range = "(created >= #{start_time.to_i} AND created <= #{end_time.to_i})"
range += " OR (timestamp >= #{start_time.to_i} AND timestamp <= #{end_time.to_i})" if include_revisions

Node.where(nid: node_ids)
.includes(:revision, :tag)
.references(:node_revision)
.where('node.status = 1')
.where(type: node_type)
.where("(created >= #{start_time.to_i} AND created <= #{end_time.to_i}) OR (timestamp >= #{start_time.to_i} AND timestamp <= #{end_time.to_i})")
.where(range)
.order('node_revisions.timestamp DESC')
.distinct
end
Expand Down

0 comments on commit 03ccee1

Please sign in to comment.