Skip to content

Commit

Permalink
Sum legacy_views into views and remove legacy_views column from node (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
alonpeer authored and digitaldina committed May 12, 2019
1 parent 5c9ccba commit 0e4d81e
Show file tree
Hide file tree
Showing 20 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/controllers/wiki_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def popular
.group('node_revisions.nid')
.order('node_revisions.timestamp DESC')
.where("node.status = 1 AND node_revisions.status = 1 AND node.nid != 259 AND (type = 'page' OR type = 'tool' OR type = 'place')")
.sort_by(&:totalviews).reverse
.sort_by(&:views).reverse
render template: 'wiki/index'
end

Expand Down
4 changes: 0 additions & 4 deletions app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,6 @@ def setup

is_impressionable counter_cache: true, column_name: :views, unique: :ip_address

def totalviews
views + legacy_views
end

def self.weekly_tallies(type = 'note', span = 52, time = Time.now)
weeks = {}
(0..span).each do |week|
Expand Down
2 changes: 1 addition & 1 deletion app/views/dashboard/_node_meta.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<% end %>
| <a href="<%= node.path %>#comments"><i class="fa fa-comment-o"></i> <%= node.fetch_comments(current_user).length %></a>
| <a href="/n/<%= node.id %>"><i class="fa fa-link"></i></a>
<span class="hidden-xs hidden-sm">| <i class="fa fa-eye"></i> <%= number_with_delimiter(node.totalviews) %></span>
<span class="hidden-xs hidden-sm">| <i class="fa fa-eye"></i> <%= number_with_delimiter(node.views) %></span>
| <i style="<% if node.likes > 0 %>color:#db4;<% end %>" class="fa fa-star-o"></i> <%= node.likes %>
<% if params[:mod] %>| <a href="#"><i class="fa fa-ban"></i></a><% end %>
<% if current_user %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/grids/_thumbnail.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<%= t('notes._notes.last_edit_by') %> <a href="/profile/<%= node.latest.author.name %>"><%= node.latest.author.name %></a>
<%= distance_of_time_in_words(Time.at(node.latest.timestamp), Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %>
<% end %>
| <i class="fa fa-eye"></i> <%= number_with_delimiter(node.totalviews) %> <span class="hidden-xs hidden-sm"><%= t('notes._notes.views') %></span>
| <i class="fa fa-eye"></i> <%= number_with_delimiter(node.views) %> <span class="hidden-xs hidden-sm"><%= t('notes._notes.views') %></span>
| <i style="<% if node.likes > 0 %>color:#db4;<% else %>color:#888;<% end %>" class="fa fa-star-o"></i> <%= node.likes %>
</small></p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/grids/_wikis.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<td><%= distance_of_time_in_words(Time.at(wiki.latest.created_at), Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %> <%= raw t('wiki._wikis.by') %>
<a href="/profile/<%= wiki.latest.author.name %>"><%= wiki.latest.author.name %></a></td>
<td><%= wiki.revisions.length %></td>
<td class="hidden-xs"><%= number_with_delimiter(wiki.totalviews) %></td>
<td class="hidden-xs"><%= number_with_delimiter(wiki.views) %></td>
<td><%= number_with_delimiter(wiki.cached_likes) %></td>
</tr>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/map/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<p><b>Published by</b> <a href="/profile/<%= @node.author.name %>"><%= @node.author.name %></a></p>
<% end %>
<p><a href="https://maps.google.com/maps?t=h&ll=<%= @node.lat %>,<%= @node.lon %>"><%= @node.lat %> N, <%= @node.lon %> E</a></p>
<p><%= @node.totalviews %> views</p>
<p><%= @node.views %> views</p>
<% if @node.map.field_ground_resolution_value %><p><b>Ground resolution: </b><%= @node.map.field_ground_resolution_value %> cm/px</p><% end %>
<p><b>Capture date:</b> <%= @node.map.captured_on.to_s %></p>
<p><b>Publication date:</b> <%= @node.map.published_on.to_s %></p>
Expand Down
2 changes: 1 addition & 1 deletion app/views/notes/_coauthored_notes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<%= t('notes._notes.last_edit_by') %> <a <% if @widget %>target="_blank"<% end %> href="/profile/<%= node.latest.author.name %>"><%= node.latest.author.name %></a>
<%= distance_of_time_in_words(Time.at(node.latest.timestamp), Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %>
<% end %>
| <i class="fa fa-eye"></i> <%= number_with_delimiter(node.totalviews) %> <span class="hidden-xs hidden-sm"><%= t('notes._notes.views') %></span>
| <i class="fa fa-eye"></i> <%= number_with_delimiter(node.views) %> <span class="hidden-xs hidden-sm"><%= t('notes._notes.views') %></span>
| <i style="<% if node.likes > 0 %>color:#db4;<% else %>color:#888;<% end %>" class="fa fa-star-o"></i> <%= node.likes %>
</small></p>
Expand Down
2 changes: 1 addition & 1 deletion app/views/notes/_draft_notes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<%= t('notes._notes.last_edit_by') %> <a <% if @widget %>target="_blank"<% end %> href="/profile/<%= node.latest.author.name %>"><%= node.latest.author.name %></a>
<%= distance_of_time_in_words(Time.at(node.latest.timestamp), Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %>
<% end %>
| <i class="fa fa-eye"></i> <%= number_with_delimiter(node.totalviews) %> <span class="hidden-xs hidden-sm"><%= t('notes._notes.views') %></span>
| <i class="fa fa-eye"></i> <%= number_with_delimiter(node.views) %> <span class="hidden-xs hidden-sm"><%= t('notes._notes.views') %></span>
| <i style="<% if node.likes > 0 %>color:#db4;<% else %>color:#888;<% end %>" class="fa fa-star-o"></i> <%= node.likes %>
</small></p>
Expand Down
2 changes: 1 addition & 1 deletion app/views/notes/_notes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<%= t('notes._notes.last_edit_by') %> <a <% if @widget %>target="_blank"<% end %> href="/profile/<%= node.latest.author.name %>"><%= node.latest.author.name %></a>
<%= distance_of_time_in_words(Time.at(node.latest.timestamp), Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %>
<% end %>
| <i class="fa fa-eye"></i> <%= number_with_delimiter(node.totalviews) %> <span class="hidden-xs hidden-sm"><%= t('notes._notes.views') %></span>
| <i class="fa fa-eye"></i> <%= number_with_delimiter(node.views) %> <span class="hidden-xs hidden-sm"><%= t('notes._notes.views') %></span>
| <i style="<% if node.likers.length > 0 %>color:#db4;<% else %>color:#888;<% end %>" class="fa fa-star-o"></i> <%= node.likers.length %>
</small></p>
Expand Down
2 changes: 1 addition & 1 deletion app/views/notes/_tagged_notes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<p style="color:#888;"><small>
<%= raw t('notes._tagged_notes.by_author_time_ago', :url1 => "/notes/author/"+node.author.name, :author => node.author.name, :time => time_ago_in_words(node.created_at)) %>
| <a href="<%= node.path %>#comments"><i style="color:#888;" class="fa fa-comment-alt"></i> <%= node.comments.size %></a>
| <%= number_with_delimiter(node.totalviews) %> <%= t('notes._tagged_notes.views') %>
| <%= number_with_delimiter(node.views) %> <%= t('notes._tagged_notes.views') %>
| <i style="color:#888;" class="fa fa-star-o"></i> <%= node.likes %>
</small></p>
<p class="hidden-lg"><%= raw strip_tags(sanitize(RDiscount.new(node.body).to_html)).truncate(150) %></p>
Expand Down
4 changes: 2 additions & 2 deletions app/views/notes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
</span>
<a class="hidden-md hidden-lg hidden-xl collapse-btn" data-toggle="collapse" href="#collapse-info" role="button" aria-expanded="false" aria-controls="collapse-info" id="collapse-button">...</a>
<span class="collapse collapse-info" id="collapse-info">
| <%= number_with_delimiter(@node.totalviews) %> <%= t('notes.show.views') %>
| <%= number_with_delimiter(@node.views) %> <%= t('notes.show.views') %>
<% if @node.comments %>
| <i class="fa fa-comment"></i>
<a href="#comments"> <%= @node.comments.length %> <%= t('notes.show.comments') %> </a>
<% end %>
| <a href="/n/<%= @node.id %>"><i class="fa fa-link"></i></a> <span class="hidden-xs hidden-sm hidden-md"><a href="/n/<%= @node.id %>">#<%= @node.id %></a></span>
</span>
<span class="hidden-xs hidden-sm hidden-print">
| <%= number_with_delimiter(@node.totalviews) %> <%= t('notes.show.views') %>
| <%= number_with_delimiter(@node.views) %> <%= t('notes.show.views') %>
<% if @node.comments %>
| <i class="fa fa-comment"></i>
<a href="#comments"> <%= @node.comments.length %> <%= t('notes.show.comments') %> </a>
Expand Down
2 changes: 1 addition & 1 deletion app/views/questions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</div>
<div class="inline">
<p><a href="/profile/<%= @node.author.name %>"><%= @node.author.name %></a> asked on <%= @node.created_at.to_s(:long) %> <% if @node.status == 0 || @node.status == 4 %>| <span class="label label-danger">UNPUBLISHED</span><% end %> <br />
<small><i class="fa fa-eye"></i> <%= number_with_delimiter(@node.totalviews) %> <span class="hidden-xs hidden-sm hidden-print ">views</span> | <i class="fa fa-comments"></i> <a href="#answers"><span id="short-comment-count"><%= @node.answers.length %></span> answers</a> | <a href="/q/<%= @node.id %>"><i class="fa fa-link"></i></a> <a href="/q/<%= @node.id %>">#<%= @node.id %></a></small></p>
<small><i class="fa fa-eye"></i> <%= number_with_delimiter(@node.views) %> <span class="hidden-xs hidden-sm hidden-print ">views</span> | <i class="fa fa-comments"></i> <a href="#answers"><span id="short-comment-count"><%= @node.answers.length %></span> answers</a> | <a href="/q/<%= @node.id %>"><i class="fa fa-link"></i></a> <a href="/q/<%= @node.id %>">#<%= @node.id %></a></small></p>
</div>

<hr style="margin-top:10px;" />
Expand Down
2 changes: 1 addition & 1 deletion app/views/tag/blog.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
| <%= distance_of_time_in_words(node.created_at, Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %>
| <a href="<%= node.path %>#comments"><i style="color:#888;" class="fa fa-comment-o"></i> <%= node.comments.size %></a>
<% if params[:controller] == "notes" && params[:action] == "popular" %>
| <%= number_with_delimiter(node.totalviews) %> <%=raw translation('tag.blog.views') %>
| <%= number_with_delimiter(node.views) %> <%=raw translation('tag.blog.views') %>
<% else %>
| <i style="color:#888;" class="fa fa-star-o"></i> <%= node.likes %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/_likes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<%= t('notes._notes.last_edit_by') %> <a <% if @widget %>target="_blank"<% end %> href="/profile/<%= like.latest.author.name %>"><%= like.latest.author.name %></a>
<%= distance_of_time_in_words(Time.at(like.latest.timestamp), Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %>
<% end %>
| <i class="fa fa-eye"></i> <%= number_with_delimiter(like.totalviews) %> <span class="hidden-xs hidden-sm"><%= t('notes._notes.views') %></span>
| <i class="fa fa-eye"></i> <%= number_with_delimiter(like.views) %> <span class="hidden-xs hidden-sm"><%= t('notes._notes.views') %></span>
| <i style="<% if like.likes > 0 %>color:#db4;<% else %>color:#888;<% end %>" class="fa fa-star-o"></i> <%= like.likes %>
</small></p>

Expand Down
2 changes: 1 addition & 1 deletion app/views/wiki/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<div class="pull-right" style="padding-top:8px;">
<span class="hidden-sm hidden-xs">
<%= number_with_delimiter(@node.totalviews) %> <%= t('wiki.show.views') %> |
<%= number_with_delimiter(@node.views) %> <%= t('wiki.show.views') %> |
<%= raw t('wiki.show.last_edited', url1: "/profile/" + @revision.author.name, author: @revision.author.name, time: time_ago_in_words(@revision.created_at)) %>
| <a href="/n/<%= @node.id %>"><i class="fa fa-link"></i></a>
<span class="hidden-xs hidden-sm hidden-md">
Expand Down
2 changes: 1 addition & 1 deletion app/views/wiki/_wikis.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<td><%= distance_of_time_in_words(Time.at(wiki.latest.created_at), Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %> <%= raw t('wiki._wikis.by') %>
<a href="/profile/<%= wiki.latest.author.name %>"><%= wiki.latest.author.name %></a></td>
<td><%= wiki.revisions.length %></td>
<td><%= number_with_delimiter(wiki.totalviews) %></td>
<td><%= number_with_delimiter(wiki.views) %></td>
<td><%= number_with_delimiter(wiki.cached_likes) %></td>
</tr>
<% end %>
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20190418230000_remove_node_legacy_views.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class RemoveNodeLegacyViews < ActiveRecord::Migration[5.2]
def up
Node.ids.each do |id|
node = Node.find(id)
node.update_columns(views: node.views + node.legacy_views)
end
remove_column :node, :legacy_views
end

def down
add_column :node, :legacy_views, :integer, default: 0
end
end
3 changes: 1 addition & 2 deletions db/schema.rb.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_04_01_093400) do
ActiveRecord::Schema.define(version: 2019_04_18_230000) do

create_table "answer_selections", force: true do |t|
t.integer "user_id"
Expand Down Expand Up @@ -234,7 +234,6 @@ ActiveRecord::Schema.define(version: 2019_04_01_093400) do
t.string "path"
t.integer "main_image_id"
t.string "slug"
t.integer "legacy_views", default: 0
t.integer "views", default: 0
t.decimal "latitude", precision: 20, scale: 17
t.decimal "longitude", precision: 20, scale: 17
Expand Down
6 changes: 3 additions & 3 deletions test/functional/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def teardown
assert_equal '0.0.0.0', Impression.last.ip_address
Impression.last.update_attribute('ip_address', '0.0.0.1')

assert_difference 'note.reload.totalviews', 1 do
assert_difference 'note.reload.views', 1 do
get :show,
params: {
author: note.author.name,
Expand All @@ -90,10 +90,10 @@ def teardown
}
end

assert_equal 2, note.reload.totalviews
assert_equal 2, note.reload.views

# same IP won't add to views twice
assert_difference 'note.reload.totalviews', 0 do
assert_difference 'note.reload.views', 0 do
get :show,
params: {
author: note.author.name,
Expand Down
4 changes: 2 additions & 2 deletions test/integration/node_unique_views_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class NodeInsertExtrasTest < ActionDispatch::IntegrationTest
assert_response :success
end

assert_difference 'nodes(:about).reload.totalviews', 0 do
assert_difference 'nodes(:about).reload.views', 0 do
assert_difference 'Impression.count', 0 do
get "/wiki/#{nodes(:about).slug}"
assert_response :success
Expand All @@ -22,7 +22,7 @@ class NodeInsertExtrasTest < ActionDispatch::IntegrationTest
assert_equal '127.0.0.1', Impression.last.ip_address
assert Impression.last.update_attributes(ip_address: '0.0.0.0')

assert_difference 'nodes(:about).reload.totalviews', 1 do
assert_difference 'nodes(:about).reload.views', 1 do
assert_difference 'Impression.count', 1 do
get "/wiki/#{nodes(:about).slug}"
assert_response :success
Expand Down

0 comments on commit 0e4d81e

Please sign in to comment.