Permalink
Browse files

As we've removed api queries before the cut-over date, simplify code. F…

…ixes #1168
  • Loading branch information...
mlandauer committed Dec 12, 2017
1 parent c27ed90 commit 8c708d056f8d7975ae891e475b94cce441713ee9
Showing with 11 additions and 27 deletions.
  1. +4 −8 app/models/scraper.rb
  2. +2 −0 app/models/user.rb
  3. +3 −3 app/views/scrapers/_data_downloads.html.haml
  4. +2 −16 spec/models/scraper_spec.rb
View
@@ -91,14 +91,10 @@ def all_watchers
(watchers + owner.watchers).uniq
end
def visible_api_queries(show_everything = false)
show_everything ? api_queries : api_queries.visible
end
# Also orders the owners by number of downloads
def download_count_by_owner(show_everything = false)
def download_count_by_owner
# TODO: Simplify this by using an association on api_query
count_by_owner_id = visible_api_queries(show_everything)
count_by_owner_id = api_queries
.group(:owner_id)
.order('count_all desc')
.count
@@ -107,8 +103,8 @@ def download_count_by_owner(show_everything = false)
end
end
def download_count(show_everything = false)
visible_api_queries(show_everything).count
def download_count
api_queries.count
end
# Given a scraper name on github populates the fields for a morph.io scraper
View
@@ -6,6 +6,8 @@ class User < Owner
has_many :contributions
has_many :scrapers_contributed_to, through: :contributions, source: :scraper
# This feature flag doesn't do anything anymore
# TODO: Remove it
def see_downloads
get_feature_switch_value(:see_downloads, false)
end
@@ -1,9 +1,9 @@
%p.scraper-data-usage
%strong
Downloaded
= pluralize(scraper.download_count(current_user && current_user.see_downloads), "time")
- if scraper.download_count(current_user && current_user.see_downloads) > 0
= pluralize(scraper.download_count, "time")
- if scraper.download_count > 0
by
- scraper.download_count_by_owner(current_user && current_user.see_downloads).each do |downloader,count|
- scraper.download_count_by_owner.each do |downloader,count|
= link_to downloader do
= owner_image(downloader, 30, true, "Downloaded #{pluralize(count, 'time')} by #{downloader.nickname}")
@@ -145,31 +145,17 @@
scraper.api_queries.create(owner: owner1, created_at: Date.new(2015, 5, 8))
scraper.api_queries.create(owner: owner2, created_at: Date.new(2015, 5, 8))
scraper.api_queries.create(owner: owner2, created_at: Date.new(2015, 5, 8))
# This api query is before the cut-off date which makes it not visible in public
scraper.api_queries.create(owner: owner2, created_at: Date.new(2015, 5, 1))
end
describe "#download_count_by_owner" do
it do
expect(scraper.download_count_by_owner(true)).to eq [[owner2, 3], [owner1, 1]]
expect(scraper.download_count_by_owner).to eq [[owner2, 2], [owner1, 1]]
end
end
describe "#download_count" do
it do
expect(scraper.download_count(true)).to eq 4
end
end
describe "#download_count_by_owner" do
it do
expect(scraper.download_count_by_owner(false)).to eq [[owner2, 2], [owner1, 1]]
end
end
describe "#download_count" do
it do
expect(scraper.download_count(false)).to eq 3
expect(scraper.download_count).to eq 3
end
end
end

0 comments on commit 8c708d0

Please sign in to comment.