<commit_before>require 'services/ticket'

class EventsController < ApplicationController
  before_action :is_logged_in?, only: [:student, :coach]

  def index
    events = [ Workshop.past.all ]
    events << Course.past.all
    events << Meeting.past.all
    events << Event.past.all
    events = events.compact.flatten.sort_by(&:date_and_time).reverse.first(40)
    events_hash_grouped_by_date = events.group_by(&:date)
    @past_events = events_hash_grouped_by_date.map.inject({}) { |hash, (key, value)| hash[key] = EventPresenter.decorate_collection(value); hash}

    events = [ Workshop.upcoming.all ]
    events << Course.upcoming.all
    events << Meeting.upcoming.all
    events << Event.upcoming.all
    events = events.compact.flatten.sort_by(&:date_and_time).group_by(&:date)
    @events = events.map.inject({}) { |hash, (key, value)| hash[key] = EventPresenter.decorate_collection(value); hash}<commit_msg>put limit on database retrievals for events page<commit_after>require 'services/ticket'

class EventsController < ApplicationController
  before_action :is_logged_in?, only: [:student, :coach]

  RECENT_EVENTS_DISPLAY_LIMIT = 40

  def index
    events = [ Workshop.past.limit(RECENT_EVENTS_DISPLAY_LIMIT) ]
    events << Course.past.limit(RECENT_EVENTS_DISPLAY_LIMIT)
    events << Meeting.past.limit(RECENT_EVENTS_DISPLAY_LIMIT)
    events << Event.past.limit(RECENT_EVENTS_DISPLAY_LIMIT)
    events = events.compact.flatten.sort_by(&:date_and_time).reverse.first(RECENT_EVENTS_DISPLAY_LIMIT)
    events_hash_grouped_by_date = events.group_by(&:date)
    @past_events = events_hash_grouped_by_date.map.inject({}) { |hash, (key, value)| hash[key] = EventPresenter.decorate_collection(value); hash}

    events = [ Workshop.upcoming.all ]
    events << Course.upcoming.all
    events << Meeting.upcoming.all
    events << Event.upcoming.all
    events = events.compact.flatten.sort_by(&:date_and_time).group_by(&:date)
    @events = events.map.inject({}) { |hash, (key, value)| hash[key] = EventPresenter.decorate_collection(value); hash}
{'fraction_non_alphanumeric': 0.12791828793774318, 'fraction_numerical': 0.0019455252918287938, 'mean_word_length': 5.05, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 3, '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': '2347270', 'n_tokens_mistral': 703, 'n_tokens_neox': 678, 'n_words': 108}