diff --git a/app/controllers/common/application/tracking.rb b/app/controllers/common/application/tracking.rb deleted file mode 100644 index b86d8c26b2f9fdefb2bf1929b9f0704d71345c79..0000000000000000000000000000000000000000 --- a/app/controllers/common/application/tracking.rb +++ /dev/null @@ -1,14 +0,0 @@ -module Common::Application::Tracking - protected - - # controllers should call this when they want to record a trackingevent. - # e.g. in order to update the page view count. - def track(options = {}) - return unless Conf.tracking - options.reverse_merge! current_user: current_user, - group: @group, - user: @user, - action: :view - ::Tracking::Page.insert options - end -end diff --git a/app/controllers/cron_controller.rb b/app/controllers/cron_controller.rb index 650d158fd3257ca918f0f20d8b4401cf536d3d7b..e75232b95a2275d9b41c10ed9372d93f31a3169d 100644 --- a/app/controllers/cron_controller.rb +++ b/app/controllers/cron_controller.rb @@ -13,10 +13,6 @@ class CronController < ActionController::Base def run case params[:id] - when 'tracking_update_hourlies' - Tracking::Page.delay.process - when 'tracking_update_dailies' - Tracking::Daily.update when 'codes_expire' Page::AccessCode.cleanup_expired when 'deliver_digests' diff --git a/app/controllers/group/home_controller.rb b/app/controllers/group/home_controller.rb index 02d083669869e8062da13a0feb1309cb18d99206..401bcd9a187f4d6222c891545b86f91cc3791c2c 100644 --- a/app/controllers/group/home_controller.rb +++ b/app/controllers/group/home_controller.rb @@ -18,7 +18,6 @@ class Group::HomeController < Group::BaseController def show @pages = Page.paginate_by_path '/descending/updated_at/limit/30/', options_for_group(@group), pagination_params - track end protected @@ -40,17 +39,11 @@ class Group::HomeController < Group::BaseController end def track_visit - memberships.update_all ['total_visits = total_visits + 1, visited_at = ?', - Time.now] + memberships.update_all(visited_at: Time.now) end def memberships @group.memberships.where(user_id: current_user) end - # helper_method :coming_from_wiki? - # will return true if we came from the wiki editor, versions or diffs - # def coming_from_wiki?(wiki) - # wiki and params[:wiki_id].to_i == wiki.id - # end end diff --git a/app/controllers/page/base_controller.rb b/app/controllers/page/base_controller.rb index 429fbdbfbad38535f178c1ab2a5fb6b0653a3d72..bd75a3037b820eafd65c575171eb018fb19aab5f 100644 --- a/app/controllers/page/base_controller.rb +++ b/app/controllers/page/base_controller.rb @@ -38,7 +38,6 @@ class Page::BaseController < ApplicationController # ... after all the others after_filter :save_if_needed, except: :create after_filter :update_viewed, only: :show - after_filter :update_view_count, only: %i[show edit create] include Page::BeforeFilters diff --git a/app/controllers/page/before_filters.rb b/app/controllers/page/before_filters.rb index 82ad67859041b12af8f22d675c640cb6dc14b469..57b1ce1580334c073f63e34e88c41bc79d86d58f 100644 --- a/app/controllers/page/before_filters.rb +++ b/app/controllers/page/before_filters.rb @@ -103,29 +103,4 @@ module Page::BeforeFilters true end - def update_view_count - return true unless @page and @page.id - action = case params[:action] - when 'create' then :edit - when 'edit' then :edit - when 'show' then :view - end - return true unless action - - group = nil - user = nil - if Conf.tracking? - if @group - group = @group - elsif @page.owner.is_a?(Group) - group = @page.owner - end - user = @page.owner if @page.owner.is_a?(User) - end - Tracking::Page.insert( - page: @page, current_user: current_user, action: action, - group: group, user: user - ) - true - end end diff --git a/app/controllers/person/home_controller.rb b/app/controllers/person/home_controller.rb index 9366215b048935d577ccd892e885f90b1c8c6f4a..bfcadbdeddd0e7087b76e19e8e26c6c92905f62f 100644 --- a/app/controllers/person/home_controller.rb +++ b/app/controllers/person/home_controller.rb @@ -12,6 +12,5 @@ class Person::HomeController < Person::BaseController def show @profile = @user.profiles.public - track end end diff --git a/app/controllers/stars_controller.rb b/app/controllers/stars_controller.rb index fceb432c4a0a3f6765094712335aba8dc2625406..ef58db0093b917e02ee6f6b5fb0398c9dfc65ebe 100644 --- a/app/controllers/stars_controller.rb +++ b/app/controllers/stars_controller.rb @@ -24,7 +24,6 @@ class StarsController < ApplicationController include Common::Tracking::Action before_filter :fetch_starred - track_actions :create def create @starred.stars.create(user: current_user) diff --git a/app/helpers/common/page/listing_helper.rb b/app/helpers/common/page/listing_helper.rb index c539079dd0420be129440d52a408d95d5ae5936b..585dd226ffcdcd3d41a74fff791486e6beaea070 100644 --- a/app/helpers/common/page/listing_helper.rb +++ b/app/helpers/common/page/listing_helper.rb @@ -40,159 +40,4 @@ module Common::Page::ListingHelper link_to(force_wrap(page.title), page_path(page)) end - def short_page_info(page) - "#{page.views_count} views / #{page.stars_count} stars".html_safe - end - - # def page_path_link(text,link_path='',image=nil) - # hash = params.dup.to_hash # hash must not be HashWithIndifferentAccess - # hash['path'] = @path.merge(link_path) # we want to preserve the @path class - - # if params[:_context] - # # special hack for landing pages using the weird dispatcher route. - # hash = "/%s?path=%s" % [params[:_context], hash[:path].to_s] - # end - # link_to text, hash - # end - - # # *NEWUI - # # - # # wrapper for the render :partial call. Options can be the following: - # # * title - # # * with_cover :: show cover image - # # * with_owner :: show owner avatar (default) - # # * checkable :: add a checkbox for selecting pages - # # * columns :: info to be displayed in page info box (see below) - # # * with_notice :: show notifications about that page - # def list_pages(options) - # render :partial => '/pages/list', :locals => options - # end - # # *NEWUI - # # - # # helper to show stars of an item (page or whatever that responds to stars_count) - # # - # def stars_for(item) - # if item.stars_count > 0 - # content_tag(:span, "%s %s" % [icon_tag('star'), item.stars_count], :class => 'star') - # else - # icon_tag('star_empty') - # end - # end - - # # *NEWUI - # # - # # render the cover of the page if it exists - # # - # def cover_for(page) - # thumbnail_img_tag(page.cover, :medium, :scale => '96x96') if page.cover - # end - - # # *NEWUI - # # - # # helper to show the information box of a page - # # - # def page_information_box_for(page, options={}) - # locals = {:page => page} - - # # status, date and username - # field = (page.updated_at > page.created_at + 1.hour) ? 'updated_at' : 'created_at' - # is_new = field == 'updated_at' - # status = is_new ? I18n.t(:page_list_heading_updated) : I18n.t(:page_list_heading_new) - # username = link_to_user(page.updated_by_login) - # date = friendly_date(page.send(field)) - # locals.merge!(:status => status, :username => username, :date => date) - - # if options.has_key?(:columns) - # locals.merge!(:views_count => page.views_count) if options[:columns].include?(:views) - # if options[:columns].include?(:stars) - # star_icon = page.stars_count > 0 ? icon_tag('star') : icon_tag('star_empty') - # locals.merge!(:stars_count => content_tag(:span, "%s %s" % [star_icon, page.stars_count])) - # end - # locals.merge!(:contributors => content_tag(:span, "%s %s" % [image_tag('/images/ui/person-dark.png'), page.stars_count])) if options[:columns].include?(:contributors) - # end - - # render :partial => 'pages/information_box', :locals => locals - # end - - # # *NEWUI - # # - # # - # # - # def title_with_link_for(page, participation = nil) - # title = link_to(h(page.title), page_url(page)) - - # # this is not used for now - # #if participation and participation.user? - # # title += " " + icon_tag("tiny_star") if participation.star? - # #else - # # #title += " " + icon_tag("tiny_pending") unless page.resolved? - # #end - # #if page.flag[:new] - # # title += " <span class='newpage'>#{I18n.t(:page_list_heading_new)}</span>" - # #end - # return title - # end - - # # *NEWUI - # # - # # - # # The list partial hands all local vars down to the page partial - # # that are in the list of allowed locals. - # def page_locals(locals) - # allowed_locals = [:columns, :checkable, :with_cover, :with_owner, :with_notice, :with_tooltip] - # locals.reject { |key,_| !allowed_locals.include? key } - # end - - # # allow bold in the excerpt, but no other html. We use special {bold} for bold. - # def escape_excerpt(str) - # h(str).gsub /\{(\/?)bold\}/, '<\1b>' - # end - - # # - # # Often when you run a page search, you will get an array of User::Participation - # # or Group::Participation objects. - # # - # # This method will convert the array to Pages if they are not. - # # - # def array_of_pages(pages) - # if pages - # if pages.first.is_a? Page - # return pages - # else - # return pages.collect{|p|p.page} - # end - # end - # end - - # # - # # Sometimes we want to divide a list of time ordered +pages+ - # # into several collections by recency. - # # - # # def divide_pages_by_recency(pages) - # # today = []; yesterday = []; week = []; later = []; - # # pages = array_of_pages(pages).dup - # # page = pages.shift - # # while page and after_day_start?(page.updated_at) - # # today << page - # # page = pages.shift - # # end - # # while page and after_yesterday_start?(page.updated_at) - # # yesterday << page - # # page = pages.shift - # # end - # # while page and after_week_start?(page.updated_at) - # # week << page - # # page = pages.shift - # # end - # # # unless today.size + yesterday.size + week.size > 0 - # # # show_time_dividers = false - # # # else - # # while page - # # later << page - # # page = pages.shift - # # end - # # # end - # # - # # return today, yesterday, week, later - # # end end diff --git a/app/helpers/common/page/listing_row_helper.rb b/app/helpers/common/page/listing_row_helper.rb deleted file mode 100644 index 2c418c8e886d3bed4a75266928727019b96cd1ab..0000000000000000000000000000000000000000 --- a/app/helpers/common/page/listing_row_helper.rb +++ /dev/null @@ -1,80 +0,0 @@ -# -# a helper for page lists in the 'detailed' view. -# - -module Common::Page::ListingRowHelper - protected - - # - # helper to show stars of an item (page or whatever that responds to stars_count) - # - # def stars_for(item) - # if item.stars_count > 0 - # content_tag(:span, "%s %s" % [icon_tag('star'), item.stars_count], :class => 'star') - # else - # icon_tag('star_empty') - # end - # end - - # - # render the cover of the page if it exists - # - def page_cover(page) - thumbnail_img_tag(page.cover, :medium, scale: '64x64') if page.cover - end - - # - # helper to show the information box of a page - # - def page_info(page, _options = {}) - date = friendly_date(page.updated_at) - user = link_to_name(page.updated_by_login) - "#{date} • #{user}<br/>#{page.views_count} views / #{page.stars_count} stars / #{page.contributors_count} voices".html_safe - - # locals = {:page => page} - - # # status, date and username - # field = (page.updated_at > page.created_at + 1.hour) ? 'updated_at' : 'created_at' - # is_new = field == 'updated_at' - # status = is_new ? I18n.t(:page_list_heading_updated) : I18n.t(:page_list_heading_new) - # username = link_to_user(page.updated_by_login) - # date = friendly_date(page.send(field)) - # locals.merge!(:status => status, :username => username, :date => date) - - # if options.has_key?(:columns) - # locals.merge!(:views_count => page.views_count) if options[:columns].include?(:views) - # if options[:columns].include?(:stars) - # star_icon = page.stars_count > 0 ? icon_tag('star') : icon_tag('star_empty') - # locals.merge!(:stars_count => content_tag(:span, "%s %s" % [star_icon, page.stars_count])) - # end - # locals.merge!(:contributors => content_tag(:span, "%s %s" % [image_tag('/images/ui/person-dark.png'), page.stars_count])) if options[:columns].include?(:contributors) - # end - - # render :partial => 'pages/information_box', :locals => locals - - # %ul.pages-status - # %li= username - # %li= status + " • " + date - # %li= "Views: #{views_count}" if local_assigns[:views_count] - # %li= contributors if local_assigns[:contributors] - # %li= stars_count if local_assigns[:stars_count] - end - - def page_summary(page) - text_with_more(page.summary, length: 300) - end - - # def owner_image(page, options={}) - # return unless page.owner - # display_name = page.owner.respond_to?(:display_name) ? page.owner.display_name : "" - # url = url_for_entity(page.owner) - # img_tag = avatar_for page.owner, 'small' - # if options[:with_tooltip] - # owner_entity = I18n.t((page.owner.is_a?(Group) ? 'group' : 'user').to_sym).downcase - # details = I18n.t(:page_owned_by, :title => page.title, :entity => owner_entity, :name => display_name) - # render :partial => 'pages/page_details', :locals => {:url => url, :img_tag => img_tag, :details => details} - # else - # link_to(img_tag, url, :class => 'imglink tooltip', :title => display_name) - # end - # end -end diff --git a/app/indices/page_terms_index.rb b/app/indices/page_terms_index.rb index edc7377cee1f290a11017142df1340e1f57c78f0..91eabf57c136f676da5524bd2545d86ff6342f36 100644 --- a/app/indices/page_terms_index.rb +++ b/app/indices/page_terms_index.rb @@ -28,7 +28,6 @@ ThinkingSphinx::Index.define 'page/terms', with: :active_record, # has :watched_by_ids, :type => :multi # counts - has :views_count has :stars_count # flags and access diff --git a/app/models/page.rb b/app/models/page.rb index 13f47f892df479fa8e6c77b190652612ee2e3c1b..3e4f88a0acdad47e182f1f7d01e83681d6fb3c70 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -35,8 +35,7 @@ require 'English' # t.string "updated_by_login" # t.string "created_by_login" # t.integer "flow", :limit => 11 -# t.integer "stars", :limit => 11, :default => 0 -# t.integer "views_count", :limit => 11, :default => 0, :null => false +# t.integer "stars_count", :limit => 11, :default => 0 # t.integer "owner_id", :limit => 11 # t.string "owner_type" # t.string "owner_name" @@ -72,7 +71,6 @@ class Page < ActiveRecord::Base include Page::Subclass # page subclassing include Page::Index # page full text searching include Page::Starring # star specific functionality - include Page::Stats # page tracking views, edits and stars include Page::HistoryTracking # page <> page_history has_many :page_notices, diff --git a/app/models/page/stats.rb b/app/models/page/stats.rb deleted file mode 100644 index de4b630ea683d45095cbac71cc55909cb768097c..0000000000000000000000000000000000000000 --- a/app/models/page/stats.rb +++ /dev/null @@ -1,38 +0,0 @@ -module Page::Stats - extend ActiveSupport::Concern - - included do - has_many :dailies, class_name: 'Tracking::Daily' - has_many :hourlies, class_name: 'Tracking::Hourly' - end - - # returns an array of view counts, [daily, weekly, monthly, all time] - def views_stats - [hourlies.sum(:views), - dailies.sum(:views, conditions: ['created_at > ?', 1.week.ago]), - dailies.sum(:views), - views_count] - end - - # returns an array of view counts, [daily, weekly, monthly, all time] - def stars_stats - [hourlies.sum(:stars), - dailies.sum(:stars, conditions: ['created_at > ?', 1.week.ago]), - dailies.sum(:stars), - stars_count] - end - - def edits_stats - [hourlies.sum(:edits), - dailies.sum(:edits, conditions: ['created_at > ?', 1.week.ago]), - dailies.sum(:edits)] - end - - # def stats_per_day - # self.dailies - # end - # - # def stats_per_hour - # self.hourlies - # end -end diff --git a/app/models/tracking/daily.rb b/app/models/tracking/daily.rb deleted file mode 100644 index fc8787981a49780777165363f795934649e68623..0000000000000000000000000000000000000000 --- a/app/models/tracking/daily.rb +++ /dev/null @@ -1,24 +0,0 @@ -# mainly MySQL-specific stuff here. -class Tracking::Daily < ActiveRecord::Base - belongs_to :page - - def self.update - begin - # this should not depend on being run every 24 hours because - # the background process can crash. - connection.execute('LOCK TABLES hourlies WRITE, dailies WRITE') - connection.execute('DELETE QUICK FROM dailies WHERE created_at < NOW() - INTERVAL 30 DAY') - connection.execute("INSERT DELAYED INTO dailies (page_id, views, stars, edits, created_at) - SELECT hourlies.page_id, sum(hourlies.views), sum(hourlies.stars), sum(hourlies.edits), DATE(hourlies.created_at) as date - FROM hourlies WHERE DATE(created_at) < DATE(UTC_TIMESTAMP() - INTERVAL 1 DAY) - GROUP BY hourlies.page_id, date") - # now that we can be sure that all hourlies have been processed we can remove the - # old ones. - # The WHERE condition here matches the one above to make sure we do not count twice. - connection.execute('DELETE QUICK FROM hourlies WHERE DATE(created_at) < DATE(UTC_TIMESTAMP() - INTERVAL 1 DAY)') - ensure - connection.execute('UNLOCK TABLES') - end - true - end -end diff --git a/app/models/tracking/hourly.rb b/app/models/tracking/hourly.rb deleted file mode 100644 index 892ee23e9904b88955b781c0b3e6c557505c729f..0000000000000000000000000000000000000000 --- a/app/models/tracking/hourly.rb +++ /dev/null @@ -1,7 +0,0 @@ -# These are the trackings per hour -# They are filled from trackings table every hour. -# dailies fetch their data from here every day. -# -class Tracking::Hourly < ActiveRecord::Base - belongs_to :page -end diff --git a/app/models/tracking/page.rb b/app/models/tracking/page.rb deleted file mode 100644 index f2511fccd168e16e6e8dfe61ea3bcdedb073d352..0000000000000000000000000000000000000000 --- a/app/models/tracking/page.rb +++ /dev/null @@ -1,183 +0,0 @@ -# um, so, yeah, basically we don't use ActiveRecord for this. -# lots of MySQL-specific stuff here. -class Tracking::Page < ActiveRecord::Base - self.table_name = 'trackings' - - # belongs_to :page - # belongs_to :group - # belongs_to :user - - # Tracks the actions quickly. Following things can be tracked: - # :current_user - user that was doing anything - # :action - one of :view, :edit, :star - # :page - page that this happened on - # :group - group context - # :user - user context - # - # This used to use "INSERT DELAYED" - however this only works with MyISAM - # and the docs say: - # Note that INSERT DELAYED is slower than a normal INSERT if the table - # is not otherwise in use. - # So it very much looks like premature optimization. - # - def self.insert(things = {}) - return false if things.empty? - execute(%( - INSERT INTO trackings(current_user_id, page_id, group_id, user_id, views, edits, stars, tracked_at) - VALUES (#{values_for_tracking(things).join(', ')}) - )) - true - end - - ## - ## Takes all the page view records that have been inserted into trackings - ## table and updates the view counts in the hourlies and membership tables with - ## this data. Afterward, all the data in trackings table is deleted. - ## - - def self.process - return if count == 0 - - unprocessed_since = last_processed_at - - lock_tables do - ## - ## update hourlies - ## - - # TODO: include edit counts in normal trackings to avoid the LEFT JOIN --azul - execute(%( - INSERT INTO hourlies (page_id, views, stars, edits, created_at) - SELECT trackings.page_id, trackings.view_count, trackings.star_count, - participations.contributor_count, - TIMESTAMPADD(HOUR, trackings.hour + 1, trackings.date) - FROM ( - SELECT page_id, SUM(views) AS view_count, SUM(stars) AS star_count, - DATE(tracked_at) AS date, HOUR(tracked_at) AS hour - FROM trackings - GROUP BY page_id, date, hour - ) AS trackings - LEFT JOIN( - SELECT page_id, COUNT(*) as contributor_count, DATE(changed_at) as date, - HOUR(changed_at) as hour - FROM user_participations - WHERE (user_participations.changed_at > '#{unprocessed_since.to_s(:db)}') - GROUP BY page_id, date, hour - ) AS participations - ON trackings.page_id = participations.page_id AND - trackings.date = participations.date AND - trackings.hour = participations.hour - )) - - ## - ## update memberships visit count - ## - - execute(%( - CREATE TEMPORARY TABLE group_view_counts - SELECT COUNT(*) AS c, current_user_id, group_id, MAX(tracked_at) as tracked_at - FROM trackings GROUP BY current_user_id, group_id - )) - execute(%( - UPDATE memberships, group_view_counts - SET memberships.visited_at = group_view_counts.tracked_at, - memberships.total_visits = memberships.total_visits + group_view_counts.c - WHERE memberships.user_id = group_view_counts.current_user_id AND - memberships.group_id = group_view_counts.group_id - )) - execute(%(DROP TEMPORARY TABLE group_view_counts)) - - ## - ## update relationships visit count - ## - - execute(%( - CREATE TEMPORARY TABLE user_view_counts - SELECT COUNT(*) AS c, user_id, current_user_id, MAX(tracked_at) as tracked_at - FROM trackings GROUP BY user_id, current_user_id - )) - execute(%( - UPDATE relationships, user_view_counts - SET relationships.visited_at = user_view_counts.tracked_at, - relationships.total_visits = relationships.total_visits + user_view_counts.c - WHERE relationships.user_id = user_view_counts.current_user_id AND - relationships.contact_id = user_view_counts.user_id - )) - execute(%(DROP TEMPORARY TABLE user_view_counts)) - - delete_all - end - - # do this after unlocking tables just to try to minimize the amount of time tables are locked - - ## - ## update page_terms - ## - - execute(%( - UPDATE page_terms,hourlies - SET page_terms.views_count = page_terms.views_count + hourlies.views - WHERE page_terms.page_id=hourlies.page_id AND - hourlies.created_at > '#{unprocessed_since.to_s(:db)}' + INTERVAL 30 MINUTE - )) - - ## - ## update pages - ## - - execute(%( - UPDATE page_terms,pages - SET pages.views_count = page_terms.views_count - WHERE pages.id=page_terms.page_id - )) - - true - end - - protected - - # returns an array of (page_id, group_id, user_id, views, edits, stars, tracked_at) - # for use in mysql values - def self.values_for_tracking(things) - views = things[:action] == :view ? 1 : 0 - edits = things[:action] == :edit ? 1 : 0 - stars = things[:action] == :star ? 1 : 0 - stars -= things[:action] == :unstar ? 1 : 0 - # for testing we need to be able to create old trackings... - time = things[:time] || Time.now.utc - time = connection.quote time.to_s(:db) - thing_ids = things.values_at(:current_user, :page, :group, :user).collect { |t| quoted_id(t) } - thing_ids.concat [views, edits, stars, time] - end - - def self.quoted_id(thing) - connection.quote(id_from(thing)) - end - - def self.id_from(thing) - if thing.nil? - nil - elsif thing.is_a?(Integer) - thing - elsif thing.is_a?(ActiveRecord::Base) - thing.id - else - nil - end - end - - def self.execute(sql) - connection.execute(sql) - end - - def self.lock_tables - execute('LOCK TABLES trackings WRITE, hourlies WRITE, memberships WRITE, relationships WRITE, user_participations WRITE') - yield - ensure - execute('UNLOCK TABLES') - end - - def self.last_processed_at - order(:tracked_at).first.try.tracked_at || Time.now - 3.month - end -end diff --git a/app/views/common/pages/_page_row.html.haml b/app/views/common/pages/_page_row.html.haml deleted file mode 100644 index 38df89f38761958b13d3e1e3c4628a94fa151a7b..0000000000000000000000000000000000000000 --- a/app/views/common/pages/_page_row.html.haml +++ /dev/null @@ -1,12 +0,0 @@ -.page_row - %span.page_info= page_info(page) - %span.page_cover= page_cover(page) - - if page.owner_id - %span.page_owner= link_to_entity(page.owner, avatar: :tiny) - %span.page_title - = (" / " + link_to(h(page.title), page_url(page))).html_safe - - else - %span.page_title= link_to h(page.title), page_url(page) - - if (summary = page_summary(page)).present? - %span.page_summary= summary - diff --git a/app/views/common/pages/_page_table_row.html.haml b/app/views/common/pages/_page_table_row.html.haml index d73a43a2ea2070a52f2b951239f58d4262ca45b9..06e4cc31e3bc2f87fce253cb9526852b87780f7c 100644 --- a/app/views/common/pages/_page_table_row.html.haml +++ b/app/views/common/pages/_page_table_row.html.haml @@ -23,5 +23,3 @@ -# - # This is a little hack. -# - # If any of the first upper five colums is hidden this one should be too. -# - # This way the last column still fits in nicely. - -# %td - -# = short_page_info(page) diff --git a/app/views/group/memberships/_list.html.haml b/app/views/group/memberships/_list.html.haml index 3337dc62ceb12190ef891395644670bccdd6caf9..41b77f16de4a2d05e0766d8ef08ca0301667788c 100644 --- a/app/views/group/memberships/_list.html.haml +++ b/app/views/group/memberships/_list.html.haml @@ -10,8 +10,6 @@ %tr %th{style: 'width:30%'}= federation_view? ? :member_groups_of_network.t : :user.t %th= :profile_member_since.t - - if !federation_view? - %th= :visits.t %th{style: 'width:30%'} - myself = @memberships.detect {|m| m.entity.name == current_user.name} - memberships = @memberships.reject {|m| m.entity.name == current_user.name} diff --git a/app/views/group/memberships/_membership.html.haml b/app/views/group/memberships/_membership.html.haml index 30f19ba9946ad8facf547102a94a1aae2f92b841..37aac35e6683ca89a586d2141f7134526d8be456 100644 --- a/app/views/group/memberships/_membership.html.haml +++ b/app/views/group/memberships/_membership.html.haml @@ -1,6 +1,4 @@ %tr{class: cycle('odd', 'even'), id: dom_id(membership)} %td= link_to_entity(membership.entity, avatar: 'small') %td= friendly_date membership.created_at - - if membership.user? - %td= membership.total_visits %td= destroy_membership_link(membership) diff --git a/app/views/page/details/_information.html.haml b/app/views/page/details/_information.html.haml index f8e7098ecaaf3bf235643955c4a59e329f234f2f..f505f6341f7b0e8eb6feb3e951745a1a93178f53 100644 --- a/app/views/page/details/_information.html.haml +++ b/app/views/page/details/_information.html.haml @@ -14,8 +14,3 @@ - r.label :updated.tcap - r.input link_to_user(@page.updated_by, avatar: 'tiny') - r.input friendly_time(@page.updated_at) - - if Conf.tracking? - - f.row do |r| - - r.label :statistics.t - - r.input render('stats') - diff --git a/app/views/page/details/_stats.html.haml b/app/views/page/details/_stats.html.haml deleted file mode 100644 index 7e12ae7ea1923dc5b1ec9fda78550ac2c6e51a0b..0000000000000000000000000000000000000000 --- a/app/views/page/details/_stats.html.haml +++ /dev/null @@ -1,30 +0,0 @@ -- views = @page.views_stats -- stars = @page.stars_stats -- edits = @page.edits_stats -%table.styled{width:'100%'} - %tr - %th - %th= I18n.t(:viewed).capitalize - %th= I18n.t(:starred).capitalize - %th= I18n.t(:edited).capitalize - %tr - %td= I18n.t(:date_today) - %td= views[0] - %td= stars[0] - %td= edits[0] - %tr - %td= I18n.t(:date_this_week) - %td= views[1] - %td= stars[1] - %td= edits[1] - %tr - %td= I18n.t(:date_this_month) - %td= views[2] - %td= stars[2] - %td= edits[2] - %tr - %td= I18n.t(:date_all_time) - %td= views[3] - %td= stars[3] - %td - diff --git a/config/misc/schedule.rb b/config/misc/schedule.rb index a57f47d313a04594ccd98fe095c1bbce287239b0..7c6f9646081d29916e65e527d04aabc84027f6c9 100644 --- a/config/misc/schedule.rb +++ b/config/misc/schedule.rb @@ -24,10 +24,6 @@ set :host, ENV['RAILS_ENV'] === 'development' ? job_type :curl, 'curl -L -XPOST http://:host/do/cron/run/:task' -every 1.hour, at: '0:30' do - curl 'tracking_update_hourlies' -end - # reindex currently takes R = 80sec. # delta index takes d = 5ms longer for each document in the delta. # Minimum total time is for delta growing up to @@ -36,11 +32,6 @@ every 6.hour, at: '0:40' do rake 'ts:index' end -every 1.day do - curl 'codes_expire' - curl 'tracking_update_dailies' -end - every 1.day, :at => '0:20 am' do curl 'deliver_digests' end diff --git a/db/migrate/20180426151421_drop_hourlies.rb b/db/migrate/20180426151421_drop_hourlies.rb new file mode 100644 index 0000000000000000000000000000000000000000..edfa38b2d4d024fb99d06a5abeaf01af7a9a11a9 --- /dev/null +++ b/db/migrate/20180426151421_drop_hourlies.rb @@ -0,0 +1,9 @@ +class DropHourlies < ActiveRecord::Migration + def change + drop_table :hourlies + end + + def down + fail ActiveRecord::IrreversibleMigration + end +end diff --git a/db/migrate/20180426151648_drop_dailies.rb b/db/migrate/20180426151648_drop_dailies.rb new file mode 100644 index 0000000000000000000000000000000000000000..ce78b0313a84ded064229020c96514d5ecdc151d --- /dev/null +++ b/db/migrate/20180426151648_drop_dailies.rb @@ -0,0 +1,9 @@ +class DropDailies < ActiveRecord::Migration + def change + drop_table :dailies + end + + def down + fail ActiveRecord::IrreversibleMigration + end +end diff --git a/db/migrate/20180426151659_drop_trackings.rb b/db/migrate/20180426151659_drop_trackings.rb new file mode 100644 index 0000000000000000000000000000000000000000..1974737d413fbd4a8a7134483306e6157accd42f --- /dev/null +++ b/db/migrate/20180426151659_drop_trackings.rb @@ -0,0 +1,9 @@ +class DropTrackings < ActiveRecord::Migration + def change + drop_table :trackings + end + + def down + fail ActiveRecord::IrreversibleMigration + end +end diff --git a/db/migrate/20180426153819_remove_views_count_from_pages.rb b/db/migrate/20180426153819_remove_views_count_from_pages.rb new file mode 100644 index 0000000000000000000000000000000000000000..60f68b88ecc18144bc1a5a61f33a6495a2ae8b0e --- /dev/null +++ b/db/migrate/20180426153819_remove_views_count_from_pages.rb @@ -0,0 +1,5 @@ +class RemoveViewsCountFromPages < ActiveRecord::Migration + def change + remove_column :pages, :views_count, :integer + end +end diff --git a/db/migrate/20180426154112_remove_views_count_from_page_terms.rb b/db/migrate/20180426154112_remove_views_count_from_page_terms.rb new file mode 100644 index 0000000000000000000000000000000000000000..7b80ea317d36488ef4a1dcf9a7c35e3553934877 --- /dev/null +++ b/db/migrate/20180426154112_remove_views_count_from_page_terms.rb @@ -0,0 +1,5 @@ +class RemoveViewsCountFromPageTerms < ActiveRecord::Migration + def change + remove_column :page_terms, :views_count, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 255f88c50ac913558ab992b9dc8c42e5b57f727b..b7f5e9ba95fdcf1188f643738ca09551a246705d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180314151824) do +ActiveRecord::Schema.define(version: 20180426154112) do create_table "activities", force: :cascade do |t| t.integer "subject_id", limit: 4 @@ -122,16 +122,6 @@ ActiveRecord::Schema.define(version: 20180314151824) do t.integer "favicon_id", limit: 4 end - create_table "dailies", force: :cascade do |t| - t.integer "page_id", limit: 4 - t.integer "views", limit: 4 - t.integer "stars", limit: 4 - t.integer "edits", limit: 4 - t.date "created_at" - end - - add_index "dailies", ["page_id"], :name => "index_dailies_on_page_id" - create_table "delayed_jobs", force: :cascade do |t| t.integer "priority", limit: 4, default: 0 t.integer "attempts", limit: 4, default: 0 @@ -243,16 +233,6 @@ ActiveRecord::Schema.define(version: 20180314151824) do add_index "groups", ["name"], :name => "index_groups_on_name" add_index "groups", ["parent_id"], :name => "index_groups_parent_id" - create_table "hourlies", force: :cascade do |t| - t.integer "page_id", limit: 4 - t.integer "views", limit: 4 - t.integer "stars", limit: 4 - t.integer "edits", limit: 4 - t.datetime "created_at" - end - - add_index "hourlies", ["page_id"], :name => "index_hourlies_on_page_id" - create_table "memberships", force: :cascade do |t| t.integer "group_id", limit: 4 t.integer "user_id", limit: 4 @@ -335,7 +315,6 @@ ActiveRecord::Schema.define(version: 20180314151824) do t.boolean "delta" t.string "media", limit: 255 t.integer "stars_count", limit: 4, default: 0 - t.integer "views_count", limit: 4, default: 0, null: false t.string "owner_name", limit: 255 t.integer "owner_id", limit: 4 end @@ -372,7 +351,6 @@ ActiveRecord::Schema.define(version: 20180314151824) do t.string "created_by_login", limit: 255 t.integer "flow", limit: 4, default: 0 t.integer "stars_count", limit: 4, default: 0 - t.integer "views_count", limit: 4, default: 0, null: false t.integer "owner_id", limit: 4 t.string "owner_type", limit: 255 t.string "owner_name", limit: 255 @@ -672,17 +650,6 @@ ActiveRecord::Schema.define(version: 20180314151824) do t.datetime "created_at", null: false end - create_table "trackings", force: :cascade do |t| - t.integer "page_id", limit: 4 - t.integer "current_user_id", limit: 4 - t.integer "group_id", limit: 4 - t.datetime "tracked_at" - t.boolean "views" - t.boolean "edits" - t.boolean "stars" - t.integer "user_id", limit: 4 - end - create_table "translations", force: :cascade do |t| t.text "text", limit: 65535 t.integer "key_id", limit: 4 diff --git a/extensions/search_filters/popularity/most_views.rb b/extensions/search_filters/popularity/most_views.rb deleted file mode 100644 index 60493eb92ef73bf522ab9c9077c9f7211158efe6..0000000000000000000000000000000000000000 --- a/extensions/search_filters/popularity/most_views.rb +++ /dev/null @@ -1,35 +0,0 @@ -SearchFilter.new('/most-views-in/:time/:unit/') do - # - # only works with mysql queries - # - mysql do |query, time, unit| - query.add_most_condition('views', time, unit) - end - - # - # ui - # - - # TODO: bring this back. disabled now because it's not working with sphinx. - # self.section = :popular_pages - self.singleton = true - self.exclude = :popular_pages - - self.description = 'pages that have been viewed the most' - html(submit_button: false) do - content_tag(:p) do - [filter_submit_button(:date_today.t, time: 24, unit: 'hours'), - filter_submit_button(:date_this_week.t, time: 7, unit: 'days'), - filter_submit_button(:date_this_month.t, time: 30, unit: 'days'), - filter_submit_button(:date_this_year.t, time: 1, unit: 'years')].join(' ').html_safe - end - end - - label do |opts| - if opts[:time] - :most_viewed.t - else - :most_viewed.t + '...' - end - end -end diff --git a/test/factories.rb b/test/factories.rb index 335718c90faeae974af10b789ccd82e97e1132c6..5becf685e2132d1096424c3b5d324956f2bea9d3 100644 --- a/test/factories.rb +++ b/test/factories.rb @@ -50,7 +50,6 @@ FactoryBot.define do stars_count 0 created_at { generate(:created_date) } updated_at { generate(:updated_date) } - views_count { rand(100) } resolved { generate(:boolean) } factory(:wiki_page, class: WikiPage) {} diff --git a/test/fixtures/page/terms.yml b/test/fixtures/page/terms.yml index 953240c801a9639cd4ecb7201c65eb8208b3f3f3..12bec259f61a5ed78adedf3bbed3e767599f114b 100644 --- a/test/fixtures/page/terms.yml +++ b/test/fixtures/page/terms.yml @@ -13,19 +13,18 @@ page_terms_001: title: A a nisi. quisque augue. maecenas mollis ipsu anticipation surprise ;&étiquette sadness resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 - created_by_login: + created_by_login: updated_by_login: blue - created_by_id: + created_by_id: updated_by_id: 4 page_updated_at: 2018-04-12 02:58:14.000000000 Z page_created_at: 2018-03-25 13:12:14.000000000 Z delta: 1 media: "[]" stars_count: 0 - views_count: 0 owner_name: rainbow owner_id: 83 page_terms_002: @@ -39,19 +38,18 @@ page_terms_002: tags: anger trust title: Llamcorper nec, massa anger trust resolved: 0 - rating: + rating: contributors_count: 0 flow: 0 - created_by_login: + created_by_login: updated_by_login: orange - created_by_id: + created_by_id: updated_by_id: 5 page_updated_at: 2018-04-11 12:24:14.000000000 Z page_created_at: 2018-04-10 08:30:14.000000000 Z delta: 1 media: "[]" stars_count: 0 - views_count: 0 owner_name: animals owner_id: 82 page_terms_003: @@ -66,19 +64,18 @@ page_terms_003: tags: sadness surprise title: A nostra, per inc sadness surprise resolved: 0 - rating: + rating: contributors_count: 0 flow: 0 - created_by_login: + created_by_login: updated_by_login: orange - created_by_id: + created_by_id: updated_by_id: 5 page_updated_at: 2018-03-17 21:51:14.000000000 Z page_created_at: 2018-02-17 13:21:14.000000000 Z delta: 1 media: "[]" stars_count: 3 - views_count: 0 owner_name: animals owner_id: 82 page_terms_004: @@ -92,19 +89,18 @@ page_terms_004: tags: anticipation _joy title: Is porta, libero ipsum mollis quam, a anticipation joy resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 - created_by_login: + created_by_login: updated_by_login: red - created_by_id: + created_by_id: updated_by_id: 8 page_updated_at: 2018-03-25 21:31:14.000000000 Z page_created_at: 2018-03-05 18:20:14.000000000 Z delta: 1 media: "[]" stars_count: 0 - views_count: 0 owner_name: rainbow owner_id: 83 page_terms_005: @@ -119,19 +115,18 @@ page_terms_005: tags: _joy love title: Arcu. integer in odio et lectus facilisis ultrice joy love resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 - created_by_login: + created_by_login: updated_by_login: orange - created_by_id: + created_by_id: updated_by_id: 5 page_updated_at: 2018-04-01 09:44:14.000000000 Z page_created_at: 2018-03-26 22:09:14.000000000 Z delta: 1 media: "[]" stars_count: 0 - views_count: 0 owner_name: animals owner_id: 82 page_terms_006: @@ -146,19 +141,18 @@ page_terms_006: tags: anger disgust title: C nisi. cras commodo. aliquam arcu. i anger disgust resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 - created_by_login: + created_by_login: updated_by_login: kangaroo - created_by_id: + created_by_id: updated_by_id: 10 page_updated_at: 2018-04-14 05:01:14.000000000 Z page_created_at: 2018-04-10 02:21:14.000000000 Z delta: 1 media: "[]" stars_count: 0 - views_count: 0 owner_name: animals owner_id: 82 page_terms_007: @@ -173,19 +167,18 @@ page_terms_007: tags: love anger title: M et risus. vivamus erat mauris, cursus n love anger resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 - created_by_login: + created_by_login: updated_by_login: red - created_by_id: + created_by_id: updated_by_id: 8 page_updated_at: 2018-04-06 10:39:14.000000000 Z page_created_at: 2018-04-04 08:50:14.000000000 Z delta: 1 media: "[]" stars_count: 0 - views_count: 0 owner_name: rainbow owner_id: 83 page_terms_008: @@ -201,19 +194,18 @@ page_terms_008: tags: sadness _joy title: T amet malesuada sadness joy resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 - created_by_login: + created_by_login: updated_by_login: orange - created_by_id: + created_by_id: updated_by_id: 5 page_updated_at: 2018-04-06 03:02:14.000000000 Z page_created_at: 2018-03-31 16:16:14.000000000 Z delta: 1 media: "[]" stars_count: 0 - views_count: 0 owner_name: animals owner_id: 82 page_terms_009: @@ -229,19 +221,18 @@ page_terms_009: tags: happiness love title: Acilisis, ris happiness love resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 - created_by_login: + created_by_login: updated_by_login: orange - created_by_id: + created_by_id: updated_by_id: 5 page_updated_at: 2018-03-22 06:25:14.000000000 Z page_created_at: 2018-02-26 16:35:14.000000000 Z delta: 1 media: "[]" stars_count: 0 - views_count: 0 owner_name: rainbow owner_id: 83 page_terms_010: @@ -257,19 +248,18 @@ page_terms_010: tags: '' title: 'Tate. class aptent taciti sociosq ' resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 - created_by_login: + created_by_login: updated_by_login: red - created_by_id: + created_by_id: updated_by_id: 8 page_updated_at: 2018-03-29 09:39:14.000000000 Z page_created_at: 2018-03-05 05:39:14.000000000 Z delta: 1 media: "[]" stars_count: 3 - views_count: 0 owner_name: rainbow owner_id: 83 page_terms_011: @@ -283,7 +273,7 @@ page_terms_011: tags: '' title: 'A ranked vote ' resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 created_by_login: quentin @@ -295,8 +285,7 @@ page_terms_011: delta: 1 media: "[]" stars_count: 0 - views_count: 0 - owner_name: + owner_name: owner_id: 8 page_terms_012: id: 4811 @@ -309,7 +298,7 @@ page_terms_012: tags: '' title: 'A task list ' resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 created_by_login: quentin @@ -321,8 +310,7 @@ page_terms_012: delta: 1 media: "[]" stars_count: 0 - views_count: 0 - owner_name: + owner_name: owner_id: 8 page_terms_013: id: 4812 @@ -335,7 +323,7 @@ page_terms_013: tags: '' title: 'Another task list ' resolved: 0 - rating: + rating: contributors_count: 0 flow: 0 created_by_login: blue @@ -347,8 +335,7 @@ page_terms_013: delta: 1 media: "[]" stars_count: 0 - views_count: 0 - owner_name: + owner_name: owner_id: 8 page_terms_014: id: 4813 @@ -360,7 +347,7 @@ page_terms_014: tags: '' title: 'Delete test ' resolved: 1 - rating: + rating: contributors_count: 0 flow: 3 created_by_login: blue @@ -372,7 +359,6 @@ page_terms_014: delta: 1 media: "[]" stars_count: 0 - views_count: 0 owner_name: blue owner_id: 14 page_terms_015: @@ -388,7 +374,7 @@ page_terms_015: tags: '' title: 'Test wiki ' resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 created_by_login: quentin @@ -400,7 +386,6 @@ page_terms_015: delta: 1 media: "[]" stars_count: 0 - views_count: 0 owner_name: blue owner_id: 14 page_terms_016: @@ -413,7 +398,7 @@ page_terms_016: tags: '' title: 'Bee ' resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 created_by_login: blue @@ -425,7 +410,6 @@ page_terms_016: delta: 1 media: "[1]" stars_count: 0 - views_count: 0 owner_name: animals owner_id: 82 page_terms_017: @@ -438,7 +422,7 @@ page_terms_017: tags: '' title: 'Sunset ' resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 created_by_login: blue @@ -450,7 +434,6 @@ page_terms_017: delta: 1 media: "[1]" stars_count: 0 - views_count: 0 owner_name: animals owner_id: 82 page_terms_018: @@ -463,7 +446,7 @@ page_terms_018: tags: '' title: 'Crabgrass ' resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 created_by_login: blue @@ -475,7 +458,6 @@ page_terms_018: delta: 1 media: "[1]" stars_count: 0 - views_count: 0 owner_name: animals owner_id: 82 page_terms_019: @@ -493,7 +475,7 @@ page_terms_019: tags: '' title: 'Survey ipsum ' resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 created_by_login: blue @@ -505,7 +487,6 @@ page_terms_019: delta: 1 media: "[]" stars_count: 0 - views_count: 0 owner_name: blue owner_id: 14 page_terms_020: @@ -518,7 +499,7 @@ page_terms_020: tags: '' title: 'A blank survey ' resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 created_by_login: blue @@ -530,8 +511,7 @@ page_terms_020: delta: 1 media: "[]" stars_count: 0 - views_count: 0 - owner_name: + owner_name: owner_id: 8 page_terms_021: id: 4820 @@ -543,19 +523,18 @@ page_terms_021: tags: '' title: 'Odit ipsa quam ' resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 created_by_login: orange updated_by_login: orange created_by_id: 5 - updated_by_id: + updated_by_id: page_updated_at: 2018-04-16 17:16:14.000000000 Z page_created_at: 2018-04-15 08:17:14.000000000 Z delta: 1 media: "[]" stars_count: 0 - views_count: 0 owner_name: orange owner_id: 15 page_terms_022: @@ -571,7 +550,7 @@ page_terms_022: tags: '' title: 'Public wiki ' resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 created_by_login: quentin @@ -583,8 +562,7 @@ page_terms_022: delta: 1 media: "[]" stars_count: 0 - views_count: 0 - owner_name: + owner_name: owner_id: 8 page_terms_023: id: 4822 @@ -611,7 +589,7 @@ page_terms_023: tags: '' title: 'Malformed wiki ' resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 created_by_login: quentin @@ -623,8 +601,7 @@ page_terms_023: delta: 1 media: "[]" stars_count: 0 - views_count: 0 - owner_name: + owner_name: owner_id: 8 page_terms_024: id: 4823 @@ -663,7 +640,7 @@ page_terms_024: tags: '' title: 'Multi section wiki ' resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 created_by_login: blue @@ -675,7 +652,6 @@ page_terms_024: delta: 1 media: "[]" stars_count: 0 - views_count: 0 owner_name: blue owner_id: 14 page_terms_025: @@ -688,7 +664,7 @@ page_terms_025: tags: '' title: 'Beauty is in the street video available ' resolved: 1 - rating: + rating: contributors_count: 0 flow: 5 created_by_login: quentin @@ -700,7 +676,6 @@ page_terms_025: delta: 1 media: "[]" stars_count: 0 - views_count: 0 owner_name: the-true-levellers owner_id: 81 page_terms_026: @@ -713,19 +688,18 @@ page_terms_026: tags: '' title: 'Page owned by the warm colors ' resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 - created_by_login: - updated_by_login: - created_by_id: + created_by_login: + updated_by_login: + created_by_id: updated_by_id: 4 page_updated_at: 2018-04-07 03:04:14.000000000 Z page_created_at: 2018-03-16 19:40:14.000000000 Z delta: 1 media: "[]" stars_count: 0 - views_count: 0 owner_name: rainbow+the-warm-colors owner_id: 831 page_terms_027: @@ -739,19 +713,18 @@ page_terms_027: tags: '' title: 'Page owned by blue, rainbow has access @test.me ' resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 - created_by_login: - updated_by_login: - created_by_id: + created_by_login: + updated_by_login: + created_by_id: updated_by_id: 4 page_updated_at: 2018-04-18 11:14:14.000000000 Z page_created_at: 2018-04-08 21:35:14.000000000 Z delta: 1 media: "[]" stars_count: 0 - views_count: 0 owner_name: blue owner_id: 14 page_terms_028: @@ -764,18 +737,17 @@ page_terms_028: tags: '' title: 'Page owned by rainbow ' resolved: 1 - rating: + rating: contributors_count: 0 flow: 0 - created_by_login: - updated_by_login: - created_by_id: + created_by_login: + updated_by_login: + created_by_id: updated_by_id: 4 page_updated_at: 2018-04-13 15:16:14.000000000 Z page_created_at: 2018-03-27 17:09:14.000000000 Z delta: 1 media: "[]" stars_count: 0 - views_count: 0 owner_name: rainbow owner_id: 83 diff --git a/test/fixtures/pages.yml b/test/fixtures/pages.yml index a057abf86be9362056bacf3bfdf016b25fa21e96..482da07e0dc1ac5267914b9a3fe351b8929b45f3 100644 --- a/test/fixtures/pages.yml +++ b/test/fixtures/pages.yml @@ -42,7 +42,6 @@ page<%=i%>: <% if rand(3) == 0 %> stars_count: <%= rand(4) %> <% end %> - views_count: <%= rand(100) %> <% if rand(3) == 0 %> resolved: false <% end %> diff --git a/test/unit/page/page_test.rb b/test/unit/page/page_test.rb index b7777beb459390e0d7cffbd06e48476d989d4209..9bd26202874c11741309e1460620c44eda42f9bf 100644 --- a/test/unit/page/page_test.rb +++ b/test/unit/page/page_test.rb @@ -260,9 +260,6 @@ class Page::BaseTest < ActiveSupport::TestCase page.update_attribute :stars_count, rand(500) assert_equal page.updated_at, last_updated_at - - page.update_attribute :views_count, rand(500) - assert_equal page.updated_at, last_updated_at end def test_even_with_timestamps_disabled_it_should_timestamp_when_create diff --git a/test/unit/pagination_test.rb b/test/unit/pagination_test.rb deleted file mode 100644 index ce6e47f32550b7f43777631125d54ec0fd4d1e37..0000000000000000000000000000000000000000 --- a/test/unit/pagination_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class PaginationTest < ActiveSupport::TestCase - def test_tracking_most_views_in_days_pagination - user = users(:blue) - group = groups(:rainbow) - - # test parameters - all_pages = group.pages.reject(&:deleted?).uniq - all_pages_ids = all_pages.collect(&:id) - per_page = 5 - total_pagination_pages = (all_pages.size.to_f / per_page).ceil - # add trackings - all_pages.each_with_index do |page, index| - # first page gets the most views - # last page gets only 1 view - # lets us test that pagination sorts them properly - (all_pages.size - index).times do - # make sure trackings will be processed into dailies - Tracking::Page.insert(current_user: user, - user: user, - group: group, - page: page, - action: :view, - time: Time.now - 3.days) - end - end - - Tracking::Page.process - Tracking::Daily.update - - # pagination group options - paginate_options = { - public: false, - callback: :options_for_group, - callback_arg_group: group, - user_ids: [user.id], - current_user: user, - group_ids: [group.id], - per_page: per_page, - page: 1 - } - - pages = Page.paginate_by_path ['most-views-in', '30', 'days'], - paginate_options - - assert_equal all_pages_ids.size, pages.total_entries - assert_equal all_pages_ids[0, per_page], pages.collect(&:id).sort - assert_equal total_pagination_pages, pages.total_pages - end -end diff --git a/test/unit/tracking/page_test.rb b/test/unit/tracking/page_test.rb deleted file mode 100644 index b82027ff596a7da1e65ca2042f73719d42b68ecb..0000000000000000000000000000000000000000 --- a/test/unit/tracking/page_test.rb +++ /dev/null @@ -1,88 +0,0 @@ -require 'test_helper' - -class Tracking::PageTest < ActiveSupport::TestCase - # otherwise transactions fail because UNLOCK TABLES implicitly commits the transaction - self.use_transactional_fixtures = false - - def setup; end - - def test_group_view_tracked - Tracking::Page.process - user = users(:blue) - group = groups(:rainbow) - assert membership = user.memberships.find_by_group_id(group.id) - assert_difference(format('group.memberships.find(%d).total_visits', membership.id)) do - Tracking::Page.insert(current_user: user, group: group) - Tracking::Page.process - end - end - - def test_user_visit_tracked - current_user = users(:blue) - user = users(:orange) - - assert_difference 'Tracking::Page.count', 3 do - 3.times { Tracking::Page.insert(current_user: current_user, user: user) } - end - assert_difference 'Tracking::Page.count', -3 do - Tracking::Page.process - end - assert_equal 3, current_user.relationships.with(user).first.total_visits - end - - def test_page_view_tracked_fully - user = users(:blue) - page = pages(:wiki) # id = 210 - group = groups(:rainbow) - action = :view - # let's clean things up first so they do not get in the way... - Tracking::Page.process - Tracking::Daily.update - Tracking::Hourly.destroy_all - assert_no_difference 'Tracking::Daily.count' do - # daily should not be created for the new hourlies - # we only create them with one day delay to avoid double counting. - assert_difference 'Tracking::Hourly.count' do - # 1, "hourly should be created for the tracked view" do - assert_tracking(user, group, page, action) - Tracking::Page.process - Tracking::Daily.update - end - end - # we create trackings for the day before yesterday here - # - so they should be counted. - # And we add another day for caution because Hourlies store the timestamp at the end - # of the hour they were tracked in. So this will be on the next day in the hour - # before midnight. - assert_difference 'Tracking::Daily.count' do - # Tracking::Hourly should be created for the tracked view - # but then removed after being processed for daily. - assert_no_difference 'Tracking::Hourly.count' do - assert_tracking(user, group, page, action, Time.now - 3.days) - Tracking::Page.process - Tracking::Daily.update - end - end - end - - private - - # Insert delayed is not delaysed for testing so this should not cause problems. - def assert_tracking(user, group, page, action, time = nil) - Tracking::Page.insert(current_user: user, group: group, page: page, action: action, time: time) - track = Tracking::Page.last - assert_equal track.current_user_id, user.id, 'User not stored correctly in Tracking' - assert_equal track.group_id, group.id, 'Group not stored correctly in Tracking' - assert_equal track.page_id, page.id, 'Page not stored correctly in Tracking' - if action != :unstar - assert_equal "#{action}s", %w[views edits stars].find { |a| Tracking::Page.last.send a }, - 'Tracking did not count the right action.' - assert_equal 1, %w[views edits stars].select { |a| Tracking::Page.last.send a }.size, - 'There shall be exactly one action counted.' - else - # TODO: check this before ActiveRecord gets in the way. - assert_equal 0, %w[views edits stars].select { |a| Tracking::Page.last.send a }.size, - 'For :unstar all values should evaluate to false.' - end - end -end diff --git a/vendor/crabgrass_plugins/crabgrass_path_finder/lib/path_finder/mysql/query.rb b/vendor/crabgrass_plugins/crabgrass_path_finder/lib/path_finder/mysql/query.rb index 8b8b6bf653d706446cd3dccb147d12abb641db40..cf7f21c247064d0444a6feca54ce5745d907871f 100644 --- a/vendor/crabgrass_plugins/crabgrass_path_finder/lib/path_finder/mysql/query.rb +++ b/vendor/crabgrass_plugins/crabgrass_path_finder/lib/path_finder/mysql/query.rb @@ -167,9 +167,6 @@ class PathFinder::Mysql::Query < PathFinder::Query def cleanup_sort_column(column) case column - when 'views' then 'views_count' - when 'stars' then 'stars_count' - # MISSING: when 'edits' then 'edits_count' when 'contributors' then 'contributors_count' when 'posts' then 'posts_count' else column @@ -177,32 +174,6 @@ class PathFinder::Mysql::Query < PathFinder::Query column.gsub(/[^[:alnum:]]+/, '_') end - def add_most_condition(what, num, unit) - unit = unit.downcase.pluralize - name = what == 'edits' ? 'contributors' : what - num.gsub!(/[^\d]+/, ' ') - if unit == 'months' - unit = 'days' - num = num.to_i * 31 - elsif unit == 'years' - unit = 'days' - num = num.to_i * 365 - end - if unit == 'days' - joins :dailies - where format('dailies.created_at > UTC_TIMESTAMP() - INTERVAL %s DAY', num) - @order << "SUM(dailies.#{what}) DESC" - select "pages.*, SUM(dailies.#{what}) AS #{name}_count" - elsif unit == 'hours' - joins :hourlies - where format('hourlies.created_at > UTC_TIMESTAMP() - INTERVAL %s HOUR', num) - @order << "SUM(hourlies.#{what}) DESC" - select "pages.*, SUM(hourlies.#{what}) AS #{name}_count" - else - return - end - end - # filter on page type or types, and maybe even media flag too! def add_type_constraint(arg) page_group, page_type, media_type = parse_page_type(arg) diff --git a/vendor/crabgrass_plugins/crabgrass_path_finder/lib/path_finder/old/mysql_filters.rb b/vendor/crabgrass_plugins/crabgrass_path_finder/lib/path_finder/old/mysql_filters.rb deleted file mode 100644 index 1d6dd391644b3c31b5637a115df30650554617c8..0000000000000000000000000000000000000000 --- a/vendor/crabgrass_plugins/crabgrass_path_finder/lib/path_finder/old/mysql_filters.rb +++ /dev/null @@ -1,316 +0,0 @@ -# -# = PathFinder::Mysql::BuilderFilters -# This contains all the filters for the different path elements. -# It gets included from the Builder. -# -# - -module PathFinder::Mysql::BuilderFilters - protected - - ## - ## ASSOCIATION - ## - - def filter_created_by(id) - @conditions << 'pages.created_by_id = ?' - @values << user_id(id) - end - - def filter_modified_by(id) - @conditions << 'user_participations.user_id = ? AND user_participations.changed_at IS NOT NULL' - @values << user_id(id) - @order << 'user_participations.changed_at DESC' if @order - end - - def filter_starred_by(id) - @conditions << 'user_participations.user_id = ? AND user_participations.star' - @values << user_id(id) - end - - def filter_watched_by(id) - @conditions << 'user_participations.user_id = ? AND user_participations.watch' - @values << user_id(id) - end - - # uses fulltext filter - def filter_person(id) - @access_filter_clause << '+' + Page.access_ids_for( - user_ids: [id] - ).first - end - - # uses fulltext filter - def filter_group(id) - @access_filter_clause << '+' + Page.access_ids_for( - group_ids: [id] - ).first - end - - ## - ## permissions - ## - - def filter_visible_to(type, id) - # this needs some thought as to what it means - end - - def filter_owned_by(type, id) - if type == 'person' - @conditions << 'pages.owner_type = "User" AND pages.owner_id = ?' - @values << user_id(id) - elsif type == 'group' - @conditions << 'pages.owner_type = "Group" AND pages.owner_id = ?' - @values << group_id(id) - end - end - - def filter_public - @access_filter_clause << '+' + Page.access_ids_for(public: true) - end - - def filter_published - @access_filter_clause << '+' + Page.access_ids_for(published: true) - end - - ## - ## page properties - ## - - # - # TODO: allow multiple OR tags instead of only AND tags - # ie "+(this_tag or_this_tag)" rather than "+this_tag +and_this_tag" - # - def filter_tag(tag_name) - @tags << '+' + Page.searchable_tag_list([tag_name]).first - end - - # filter on page type or types, and maybe even media flag too! - # eg values: - # media-image+file, media-image+gallery, file, - # text+wiki, text, wiki - def filter_type(arg) - return if arg == 'all' - - if arg =~ /[\+\ ]/ - page_group, page_type = arg.split(/[\+\ ]/) - elsif Page.is_page_group?(arg) - page_group = arg - elsif Page.is_page_type?(arg) - page_type = arg - end - - if page_group =~ /^media-(image|audio|video|document)$/ - media_type = page_group.sub(/^media-/, '') - @conditions << "pages.is_#{media_type} = ?" # only safe because of regexp in if - @values << true - end - - @flow = :announcement if page_type == 'announcement' - - if page_type - @conditions << 'pages.type = ?' - @values << Page.param_id_to_class_name(page_type) # eg 'RateManyPage' - elsif page_group - @conditions << 'pages.type IN (?)' - @values << Page.class_group_to_class_names(page_group) # eg ['WikiPage','SurveyPage'] - else - # we didn't find either a type or a group for arg - # just search for arg. this should return an empty set - @conditions << 'pages.type = ?' - @values << arg # example 'bad_page_type' - end - end - - # def filter_name(name) - # @conditions << 'pages.name = ?' - # @values << name - # end - - # - # in case sphinx is not available, but this should really never be used. - # - def filter_text(text) - @conditions << 'pages.title LIKE ?' - @values << "%#{text}%" - end - - ## - ## Popularity - ## - - def filter_most(what, num, unit) - unit = unit.downcase.pluralize - name = what == 'edits' ? 'contributors' : what - num.gsub!(/[^\d]+/, ' ') - if unit == 'days' - @conditions << format('dailies.created_at > UTC_TIMESTAMP() - INTERVAL %s DAY', num) - @order << "SUM(dailies.#{what}) DESC" - @select = "pages.*, SUM(dailies.#{what}) AS #{name}_count" - elsif unit == 'hours' - @conditions << format('hourlies.created_at > UTC_TIMESTAMP() - INTERVAL %s HOUR', num) - @order << "SUM(hourlies.#{what}) DESC" - @select = "pages.*, SUM(hourlies.#{what}) AS #{name}_count" - else - return - end - end - - def filter_most_views(num, unit) - filter_most('views', num, unit) - end - - def filter_most_edits(num, unit) - filter_most('edits', num, unit) - end - - def filter_most_stars(num, unit) - filter_most('stars', num, unit) - end - - ## - ## sorting - ## - - def filter_ascending(sortkey) - sortkey = 'views_count' if sortkey == 'views' - sortkey.gsub!(/[^[:alnum:]]+/, '_') - @order << format('%s.%s ASC', @klass.table_name, sortkey) - end - - def filter_descending(sortkey) - sortkey = 'views_count' if sortkey == 'views' - sortkey.gsub!(/[^[:alnum:]]+/, '_') - @order << format('%s.%s DESC', @klass.table_name, sortkey) - end - - ## - ## BOOLEAN - ## - - def filter_or - @or_clauses << @conditions - @conditions = [] - end - - ## - ## LIMIT - ## - - def filter_limit(limit) - offset = 0 - limit, offset = limit.split('-') if limit.instance_of? String - @limit = limit.to_i if limit - @offset = offset.to_i if offset - end - - # def filter_per_page(per_page) - # @page ||= 1 - # @per_page = per_page.to_i - # end - - ## - ## TIME AND DATE FILTERS - ## - - # # for your health, use this to convert local time to utc - # # the dates in @values should be utc, all other date variables - # # should be local time. - # #++ - # def to_utc(time) # :nodoc: - # time = time.to_time if time.is_a? Date - # Time.zone.local_to_utc(time) - # end - - # # def filter_starts - # # @date_field = "starts_at" - # # end - # # - # # def filter_created - # # @date_field = "created_at" - # # end - - # def filter_updated - # @date_field = "updated_at" - # end - - # def filter_after(date) - ## if date == 'now' - ## date = Time.now - ## else - ## if date == 'today' - ## date = to_utc(local_now.at_beginning_of_day) - ## else - ## year, month, day = date.split('-') - ## date = to_utc( Time.in_time_zone(year, month, day) ) - ## end - ## end - ## @conditions << "pages.#{@date_field} >= ?" - ## @values << date.to_s(:db) - # end - - # def filter_before(date) - ## if date == 'now' - ## date = Time.now - ## else - ## year, month, day = date.split('-') - ## date = to_utc Time.in_time_zone(year, month, day) - ## end - ## @conditions << "pages.#{@date_field} <= ?" - ## @values << date.to_s(:db) - # end - - # def filter_changed - # @conditions << 'pages.updated_at > pages.created_at' - # end - - # # def filter_upcoming - # # @conditions << 'pages.starts_at > ?' - # # @values << Time.now - # # @order << 'pages.starts_at DESC' if @order - # # end - - # def filter_ago(near,far) - # near = near.to_i.days.ago - # far = far.to_i.days.ago - # @conditions << 'pages.updated_at < ? and pages.updated_at > ? ' - # @values << to_utc(near) << to_utc(far) - # end - - # def filter_created_after(date) - ## year, month, day = date.split('-') - ## date = to_utc Time.in_time_zone(year, month, day) - ## @conditions << 'pages.created_at > ?' - ## @values << date.to_s(:db) - # end - - # def filter_created_before(date) - ## year, month, day = date.split('-') - ## date = to_utc Time.in_time_zone(year, month, day) - ## @conditions << 'pages.created_at < ?' - ## @values << date.to_s(:db) - # end - - # #-- - # # 2008 --> all pages from 2008-1-1 up to but not including 2009-1-1 - # # 2008-12 --> all pages from 2008-12-1 up to but not including 2009-1-1 - # # 2008-12-5 --> all pages from 2008-12-5 up to but not including 2008-12-6 - # #++ - # def filter_date(date) - # start_year, start_month, start_day = date.split('-') - # if start_year.nil? - # return # no way to deal with an empty date - # elsif start_month.nil? - # start_time = Date.new(start_year.to_i, 1, 1) - # end_time = start_time + 1.year - # elsif start_day.nil? - # start_time = Date.new(start_year.to_i, start_month.to_i, 1) - # end_time = start_time + 1.month - # else - # start_time = Date.new(start_year.to_i, start_month.to_i, start_day.to_i) - # end_time = start_time + 1.day - # end - # @conditions << "pages.`#{@date_field}` >= ? AND pages.`#{@date_field}` < ?" - # @values << to_utc(start_time) << to_utc(end_time) - # end -end diff --git a/vendor/crabgrass_plugins/crabgrass_path_finder/lib/path_finder/old/sphinx_builder.rb b/vendor/crabgrass_plugins/crabgrass_path_finder/lib/path_finder/old/sphinx_builder.rb deleted file mode 100644 index 04b2831717cd5bace726867f00d047ffb84f10cf..0000000000000000000000000000000000000000 --- a/vendor/crabgrass_plugins/crabgrass_path_finder/lib/path_finder/old/sphinx_builder.rb +++ /dev/null @@ -1,103 +0,0 @@ -# -# PathFinder::Sphinx::Builder -# -# Concrete subclass of PathFinder::Builder with support for sphinx as the backend. -# -# This code is called by find_by_path() in PathFinder::FindByPath -# -class PathFinder::Sphinx::Builder < PathFinder::Builder - include PathFinder::Sphinx::BuilderFilters - - def initialize(path, options, klass) - super - - @original_path = path - @original_options = options - @klass = klass # What are we searching Pages or Posts? - - # filter on access_ids: - # we use an array for @with (rather than a hash), so that we - # can have multiple constraints on the same key. See README_GEMS - # for details on this hackery. - @with = [] - if options[:group_ids] or options[:user_ids] or options[:public] - @with << ['access_ids', Page.access_ids_for( - public: options[:public], - group_ids: options[:group_ids], - user_ids: options[:user_ids] - )] - end - if options[:secondary_group_ids] or options[:secondary_user_ids] - @with << ['access_ids', Page.access_ids_for( - group_ids: options[:secondary_group_ids], - user_ids: options[:secondary_user_ids] - )] - end - if options[:site_ids] - @with << ['access_ids', Page.access_ids_for( - site_ids: options[:site_ids] - )] - end - - @without = {} - @conditions = {} - @order = '' - @search_text = '' - @per_page = options[:per_page] || SECTION_SIZE - @page = options[:page] || 1 - - apply_filters_from_path(path) - @order = @order.presence - end - - def search - # the default sort is '@relevance DESC', but this can create rather odd - # results because you might get relevent pages from years ago. So, if there - # is no explicit order set, we want to additionally sort by page_updated_at. - if @order.nil? - @sort_mode = :extended - @order = '@relevance DESC, page_updated_at DESC' - end - - # puts "Page::Terms.search #{@search_text.inspect}, :with => #{@with.inspect}, :without => #{@without.inspect}, :page => #{@page.inspect}, :per_page => #{@per_page.inspect}, :order => #{@order.inspect}, :include => :page" - - # 'with' is used to limit the query using an attribute. - # 'conditions' is used to search for on specific fields in the fulltext index. - # 'search_text' is used to search all the fulltext index. - page_terms = Page::Terms.search @search_text, - page: @page, per_page: @per_page, include: :page, - with: @with, without: @without, conditions: @conditions, - order: @order, sort_mode: @sort_mode - - # page_terms has all of the will_paginate magic included, it just needs to - # actually have the pages, which we supply with page_terms.replace(pages). - pages = [] - page_terms.each do |pt| - pages << pt.page unless pt.nil? - # Why might pt be nil? If the Page::Terms was destroyed but sphinx has - # not been reindex. This should not ever happen when things are working, - # but sometimes it does, and if it does we don't want to bomb out. - end - page_terms.replace(pages) - end - - def find - search - rescue ThinkingSphinx::ConnectionError - PathFinder::Mysql::Builder.new(@original_path, @original_options, @klass).find # fall back to mysql - end - - def paginate - search # sphinx search *always* paginates - rescue ThinkingSphinx::ConnectionError - PathFinder::Mysql::Builder.new(@original_path, @original_options, @klass).paginate # fall back to mysql - end - - def count - Page::Terms.search_for_ids(@search_text, with: @with, without: @without, - page: @page, per_page: @per_page, conditions: @conditions, - order: @order, include: :page).size - rescue ThinkingSphinx::ConnectionError - PathFinder::Mysql::Builder.new(@original_path, @original_options, @klass).count # fall back to mysql - end -end diff --git a/vendor/crabgrass_plugins/crabgrass_path_finder/lib/path_finder/old/sphinx_filters.rb b/vendor/crabgrass_plugins/crabgrass_path_finder/lib/path_finder/old/sphinx_filters.rb deleted file mode 100644 index 58224d20803ba4e30059f7562449883d1c002345..0000000000000000000000000000000000000000 --- a/vendor/crabgrass_plugins/crabgrass_path_finder/lib/path_finder/old/sphinx_filters.rb +++ /dev/null @@ -1,236 +0,0 @@ -# -# -# THIS FILE IS NOT USED -# -# - -# = PathFinder::Sphinx::BuilderFilters -# -# This contains all the filters for the different path elements. -# It gets included from the Builder. -# -# -# These fields are defines as sphinx attributes, and should use -# @with instead of @conditions: -# -# :sphinx_internal_id, :class_crc, :sphinx_deleted, :title_sort, -# :page_type_sort, :created_by_login_sort, :updated_by_login_sort, -# :owner_name_sort, :page_created_at, :page_updated_at, :views_count, -# :created_by_id, :updated_by_id, :resolved, :stars_count, :access_ids, -# :media -# -# NOTE: @conditions is a hash, @with is an array. -# -# in sphinx, attributes are numeric only. -# - -module PathFinder::Sphinx::BuilderFilters - protected - - def filter_unread - raise Exception.new('sphinx cannot search for unread') - end - - def filter_pending - @with << [:resolved, 0] - end - - def filter_interesting - raise Exception.new('sphinx cannot search for interesting') - end - - def filter_watching - raise Exception.new('sphinx cannot search for watching') - end - - def filter_inbox - raise Exception.new('sphinx cannot search for inbox') - end - - def filter_attending - raise Exception.new('sphinx cannot search for attending') - end - - def filter_starred - raise Exception.new('sphinx cannot search for starred') - end - - def filter_changed - raise Exception.new('sphinx cannot search for changed') - end - - #-- - ### Time finders - # dates in database are UTC - # we assume the values pass to the finder are local - #++ - - # def filter_starts - # @date_field = :created_at - # end - # - # def filter_after(date) - # if date == 'now' - # date = Time.zone.now - # else - # if date == 'today' - # date = to_utc(local_now.at_beginning_of_day) - # else - # year, month, day = date.split('-') - # date = to_utc Time.in_time_zone(year, month, day) - # end - # end - # @conditions[@date_field] = range(date, date+100.years) - # end - # - # def filter_before(date) - # if date == 'now' - # date = Time.now - # else - # if date == 'today' - # date = Time.zone.now.to_date - # else - # year, month, day = date.split('-') - # date = to_utc Time.in_time_zone(year, month, day) - # end - # end - # @conditions[@date_field] = range(date-100.years, date) - # end - # - # def filter_upcoming - # @conditions[:starts_at] = range(Time.zone.now, Time.zone.now + 100.years) - # @order << 'pages.starts_at DESC' - # end - - def filter_ago(near, far) - @with << [:page_updated_at, range(far.to_i.days.ago, near.to_i.days.ago)] - end - - def filter_created_after(date) - year, month, day = date.split('-') - date = to_utc Time.in_time_zone(year, month, day) - @with << [:page_created_at, range(date, date + 100.years)] - end - - def filter_created_before(date) - year, month, day = date.split('-') - date = to_utc Time.in_time_zone(year, month, day) - @with << [:page_created_at, range(date - 100.years, date)] - end - - # def filter_month(month) - # year = Time.zone.now.year - # @conditions[@date_field] = range(Time.in_time_zone(year,month), Time.in_time_zone(year,month+1)) - # end - # - # def filter_year(year) - # @conditions[:date_field] = range(Time.in_time_zone(year), Time.in_time_zone(year+1)) - # end - - #### - - # filter on page type or types, and maybe even media flag too! - # eg values: - # media-image+file, media-image+gallery, file, - # text+wiki, text, wiki - def filter_type(arg) - if arg =~ /[\+\ ]/ - page_group, page_type = arg.split(/[\+\ ]/) - elsif Page.is_page_group?(arg) - page_group = arg - elsif Page.is_page_type?(arg) - page_type = arg - end - - if page_group =~ /^media-(image|audio|video|document)$/ - media_type = page_group.sub(/^media-/, '').to_sym - @with << [:media, MEDIA_TYPE[media_type]] # indexed as multi array of ints. - end - - if page_type - @conditions[:page_type] = Page.param_id_to_class_name(page_type) - elsif page_group - @conditions[:page_type] = Page.class_group_to_class_names(page_group).join('|') - else - # we didn't find either a type or a group for arg - # just search for arg. this should return an empty set - @conditions[:page_type] = arg.dup - end - end - - def filter_person(id) - @with << [:access_ids, Page.access_ids_for(user_ids: [id])] - end - - def filter_group(id) - @with << [:access_ids, Page.access_ids_for(group_ids: [id])] - end - - def filter_created_by(id) - @with << [:created_by_id, id] - end - - def filter_not_created_by(id) - @without[:created_by_id] ||= '' - @without[:created_by_id] += " #{id}" - end - - def filter_tag(tag_name) - @conditions[:tags] ||= '' - @conditions[:tags] += " #{tag_name}" - end - - def filter_name(name) - @conditions[:name] ||= '' - @conditions[:name] += " #{name}" - end - - def filter_stars(star_count) - @with << [:stars_count, range(star_count, 10_000)] - end - - def filter_starred - filter_stars(1) - end - - #-- - #### sorting #### - #++ - - def filter_ascending(sortkey) - if sortkey == 'updated_at' or sortkey == 'created_at' - sortkey = 'page_' + sortkey - end - @order << " #{sortkey} ASC" - end - - def filter_descending(sortkey) - if sortkey == 'updated_at' or sortkey == 'created_at' - sortkey = 'page_' + sortkey - end - @order << " #{sortkey} DESC" - end - - #-- - ### LIMIT ### - #++ - - def filter_limit(limit) - offset = 0 - limit, offset = limit.split('-') if limit.instance_of? String - @per_page = limit.to_i if limit - @page = ((offset.to_f / limit.to_f) + 1).floor.to_i if @per_page > 0 - end - - def filter_text(text) - @search_text += " #{text}" - end - - #-- - ### HELPER ### - #++ - - def range(min, max) - min.to_i..max.to_i - end -end diff --git a/vendor/crabgrass_plugins/crabgrass_path_finder/lib/path_finder/sphinx/query.rb b/vendor/crabgrass_plugins/crabgrass_path_finder/lib/path_finder/sphinx/query.rb index 0956c4fee9f5d80d1202fed719a0ec005918211c..bb7b1cacd0a30ed9342c333698242c555e44c41f 100644 --- a/vendor/crabgrass_plugins/crabgrass_path_finder/lib/path_finder/sphinx/query.rb +++ b/vendor/crabgrass_plugins/crabgrass_path_finder/lib/path_finder/sphinx/query.rb @@ -13,12 +13,12 @@ # # When you want to search on a string field, you use @conditions. # -# These fields are defines as sphinx attributes, and should use +# These fields are defined as sphinx attributes, and should use # @with instead of @conditions: # # :sphinx_internal_id, :class_crc, :sphinx_deleted, :title_sort, # :page_type_sort, :created_by_login_sort, :updated_by_login_sort, -# :owner_name_sort, :page_created_at, :page_updated_at, :views_count, +# :owner_name_sort, :page_created_at, :page_updated_at, # :created_by_id, :updated_by_id, :resolved, :stars_count, :access_ids, # :media, :owner_id # @@ -198,9 +198,6 @@ class PathFinder::Sphinx::Query < PathFinder::Query column = case column when 'updated_at' then 'page_updated_at' when 'created_at' then 'page_created_at' - when 'views' then 'views_count' - when 'stars' then 'stars_count' - # MISSING: when 'edits' then 'edits_count' missing # MISSING: when 'contributors' then 'contributors_count' # MISSING: when 'posts' then 'posts_count' else column