<commit_before># = PathFinder::Mysql::Builder
#
# Concrete subclass of PathFinder::Builder
#
# == Usage:
# This class generates the SQL and makes the call to find_by_sql.
# It is called from find_by_path in PathFinder::FindByPath. Look there
# for an example how to use it.
#
# == Resolving Permissions
# It uses a fulltext index on page_terms in order to resolve permissions for pages.
# This bypasses potentially really hairy four-way joins on user_participations
# and group_participations tables.
# (not to mention a potential 5th,6th,7th joins for tags, ugh!)
#
# An example query:
#
#  SELECT * FROM pages
#  JOIN page_terms ON pages.id = page_terms.page_id
#  WHERE
#    MATCH(page_terms.access_ids)
#    AGAINST('+(0001 0011 0081 0082) +0081' IN BOOLEAN MODE)
#
# * this is an inner join, because *every* page should
#   have a corresponding page_term.
# * page_term.access_ids is a text column with a fulltext index.
# * the format of the values in access_ids is thus:
#   * user ids are prefixed with 1
#   * group ids are prefixed with 8
#   * every id is at least four characters in length, 
#     padded with zeros if necessary.
#   * if page is public, id 0001 is present.
#
# So, suppose the current user was id 1, and they were
# members of groups 1 and 2. 
#
# To find all the pages of group 1 that current_user may access:
#
#    (current_user.id OR public OR current_user.all_group_ids) AND group.id
#
# In fulltext boolean mode search on access_ids, this becomes:
#
#    +(0011 0001 0081 0082) +0081
#
# The first part of this condition is called the access_me_clause. This is where we
# resolve the question "what does current user have access to?". This clause is
# based entirely on the current_user variable.
#
# The next AND clause is called the access_target_clause. This is where we ask "who's
# pages are we searching for?". This clause is based entirely on what options
# are used (ie options_for_group() or options_for_user())
#
# There can be additional AND clauses. These are called access_filter_clauses.
# This is for additional limits that pop up in the path itself. It is based
# entirely on what is in the filter path.
#

class PathFinder::Mysql::Builder < PathFinder::Builder

  include PathFinder::Mysql::BuilderFilters

  public

  # initializes all the arrays for conditions, aliases, clauses and so on
  def initialize(path, options)

    ## page_terms access clauses
    ## (within each clause, the values are OR'ed, but the clauses are AND'ed
    ##  together in the query).
    if options[:group_ids] or options[:user_ids] or options[:public]
      @access_me_clause = "+(%s)" % Page.access_ids_for(
        :public    => options[:public],
        :group_ids => options[:group_ids],
        :user_ids  => options[:user_ids]
      ).join(' ')
    end
    if options[:secondary_group_ids] or options[:secondary_user_ids]
      @access_target_clause = "+(%s)" % Page.access_ids_for(
        :group_ids => options[:secondary_group_ids],
        :user_ids  => options[:secondary_user_ids]
      ).join(' ')
    end
    if options[:site_ids]
      @access_site_clause = "+(%s)" % Page.access_ids_for(
        :site_ids => options[:site_ids]
      ).join(' ')
    end
    @access_filter_clause = [] # to be used by path filters

    ## page stuff
    @path        = cleanup_path(path)
    @conditions  = []
    @values      = []
    @order       = []
    @tags        = []
    @or_clauses  = []
    @and_clauses = []
    @flow        = options[:flow]
    @date_field  = 'created_at'

    # magic will_paginate paginating (count required)
    @per_page    = 2 # options[:per_page]
    @page        = options[:page]
    # limiting   (count not required)
    @limit       = nil
    @offset      = nil<commit_msg>forgot to remove debugging setting.<commit_after># = PathFinder::Mysql::Builder
#
# Concrete subclass of PathFinder::Builder
#
# == Usage:
# This class generates the SQL and makes the call to find_by_sql.
# It is called from find_by_path in PathFinder::FindByPath. Look there
# for an example how to use it.
#
# == Resolving Permissions
# It uses a fulltext index on page_terms in order to resolve permissions for pages.
# This bypasses potentially really hairy four-way joins on user_participations
# and group_participations tables.
# (not to mention a potential 5th,6th,7th joins for tags, ugh!)
#
# An example query:
#
#  SELECT * FROM pages
#  JOIN page_terms ON pages.id = page_terms.page_id
#  WHERE
#    MATCH(page_terms.access_ids)
#    AGAINST('+(0001 0011 0081 0082) +0081' IN BOOLEAN MODE)
#
# * this is an inner join, because *every* page should
#   have a corresponding page_term.
# * page_term.access_ids is a text column with a fulltext index.
# * the format of the values in access_ids is thus:
#   * user ids are prefixed with 1
#   * group ids are prefixed with 8
#   * every id is at least four characters in length, 
#     padded with zeros if necessary.
#   * if page is public, id 0001 is present.
#
# So, suppose the current user was id 1, and they were
# members of groups 1 and 2. 
#
# To find all the pages of group 1 that current_user may access:
#
#    (current_user.id OR public OR current_user.all_group_ids) AND group.id
#
# In fulltext boolean mode search on access_ids, this becomes:
#
#    +(0011 0001 0081 0082) +0081
#
# The first part of this condition is called the access_me_clause. This is where we
# resolve the question "what does current user have access to?". This clause is
# based entirely on the current_user variable.
#
# The next AND clause is called the access_target_clause. This is where we ask "who's
# pages are we searching for?". This clause is based entirely on what options
# are used (ie options_for_group() or options_for_user())
#
# There can be additional AND clauses. These are called access_filter_clauses.
# This is for additional limits that pop up in the path itself. It is based
# entirely on what is in the filter path.
#

class PathFinder::Mysql::Builder < PathFinder::Builder

  include PathFinder::Mysql::BuilderFilters

  public

  # initializes all the arrays for conditions, aliases, clauses and so on
  def initialize(path, options)

    ## page_terms access clauses
    ## (within each clause, the values are OR'ed, but the clauses are AND'ed
    ##  together in the query).
    if options[:group_ids] or options[:user_ids] or options[:public]
      @access_me_clause = "+(%s)" % Page.access_ids_for(
        :public    => options[:public],
        :group_ids => options[:group_ids],
        :user_ids  => options[:user_ids]
      ).join(' ')
    end
    if options[:secondary_group_ids] or options[:secondary_user_ids]
      @access_target_clause = "+(%s)" % Page.access_ids_for(
        :group_ids => options[:secondary_group_ids],
        :user_ids  => options[:secondary_user_ids]
      ).join(' ')
    end
    if options[:site_ids]
      @access_site_clause = "+(%s)" % Page.access_ids_for(
        :site_ids => options[:site_ids]
      ).join(' ')
    end
    @access_filter_clause = [] # to be used by path filters

    ## page stuff
    @path        = cleanup_path(path)
    @conditions  = []
    @values      = []
    @order       = []
    @tags        = []
    @or_clauses  = []
    @and_clauses = []
    @flow        = options[:flow]
    @date_field  = 'created_at'

    # magic will_paginate paginating (count required)
    @per_page    = options[:per_page]
    @page        = options[:page]
    # limiting   (count not required)
    @limit       = nil
    @offset      = nil
{'fraction_non_alphanumeric': 0.09558040468583599, 'fraction_numerical': 0.014243876464323749, 'mean_word_length': 3.317816091954023, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4310680', 'n_tokens_mistral': 2416, 'n_tokens_neox': 2303, 'n_words': 850}