<commit_before>require 'subscriptions_manager'

##
# Class with methods related to changing the read/unread state of entries.

class EntryStateManager

  ##
  # Change the read or unread state of several entries, for a given user.
  #
  # Receives as arguments:
  # - the entry to be changed state
  # - the state in which to put it. Supported values are only "read" and "unread"; this method
  # does nothing if a different value is passed
  # - the user for which the state will be set.
  # - update_older (optional): boolean to indicate whether other entries in the same feed **older** than
  # the one passed as argument are to be changed state as well.
  #
  # If the update_older optional named argument is passed as true, all entries in the same feed as the
  # passed entry which either:
  # - have an older publish date than the passed entry
  # - or have the same publish date but a smaller id
  # are considered to be older and therefore set as read or unread depending on the "state" argument.

  def self.change_entries_state(entry, state, user, update_older: false)
    if state == 'read'
      read = true
    elsif state == 'unread'
      read = false
    else
      return nil
    end

    entry_state = EntryState.where(user_id: user.id, entry_id: entry.id).first
    entry_state.read = read
    entry_state.save!

    if update_older
      entries = Entry.where('feed_id=? AND (published < ? OR  (published == ? AND id < ?) )',
                            entry.feed_id, entry.published, entry.published, entry.id)
      entries.each do |e|
        entry_state = EntryState.where(user_id: user.id, entry_id: e.id).first<commit_msg>Attempt to solve a MySQL syntax error when marking all entries in a feed as read.<commit_after>require 'subscriptions_manager'

##
# Class with methods related to changing the read/unread state of entries.

class EntryStateManager

  ##
  # Change the read or unread state of several entries, for a given user.
  #
  # Receives as arguments:
  # - the entry to be changed state
  # - the state in which to put it. Supported values are only "read" and "unread"; this method
  # does nothing if a different value is passed
  # - the user for which the state will be set.
  # - update_older (optional): boolean to indicate whether other entries in the same feed **older** than
  # the one passed as argument are to be changed state as well.
  #
  # If the update_older optional named argument is passed as true, all entries in the same feed as the
  # passed entry which either:
  # - have an older publish date than the passed entry
  # - or have the same publish date but a smaller id
  # are considered to be older and therefore set as read or unread depending on the "state" argument.

  def self.change_entries_state(entry, state, user, update_older: false)
    if state == 'read'
      read = true
    elsif state == 'unread'
      read = false
    else
      return nil
    end

    entry_state = EntryState.where(user_id: user.id, entry_id: entry.id).first
    entry_state.read = read
    entry_state.save!

    if update_older
      entries = Entry.where('feed_id=? AND (published < ? OR  (published = ? AND id < ?) )',
                            entry.feed_id, entry.published, entry.published, entry.id)
      entries.each do |e|
        entry_state = EntryState.where(user_id: user.id, entry_id: e.id).first
{'fraction_non_alphanumeric': 0.07543807543807544, 'fraction_numerical': 0.0, 'mean_word_length': 3.0143027413587604, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4120498', 'n_tokens_mistral': 955, 'n_tokens_neox': 943, 'n_words': 422}