<commit_before>module Crowdblog
  class User < ActiveRecord::Base
    has_many :authored_posts, inverse_of: :author,
        foreign_key: 'author_id', class_name: 'Post'
    has_many :published_posts, -> { where :state => 'published' }, inverse_of: :author,
        foreign_key: 'author_id', class_name: 'Post',
        order: 'published_at DESC'
  	has_one  :last_post, -> { where :state => 'published' }, class_name: 'Post',
  			foreign_key: :author_id,
  			order: 'published_at DESC, created_at DESC, id DESC'

    def is_publisher?
      true
    end

    def last_post_at
      last_post.try(:published_at)
    end

    def last_published_at
      published_posts.first ? published_posts.first.published_at : nil
    end<commit_msg>Fix some scopes<commit_after>module Crowdblog
  class User < ActiveRecord::Base
    has_many :authored_posts, inverse_of: :author,
        foreign_key: 'author_id', class_name: 'Post'
    has_many :published_posts, -> {
          where(state: 'published').
          order('published_at DESC')
        },
        inverse_of: :author,
        foreign_key: 'author_id', class_name: 'Post'
    has_one  :last_post, -> {
          where(state: 'published').
          order('published_at DESC, created_at DESC, id DESC')
        },
        class_name: 'Post',
        foreign_key: :author_id

    def is_publisher?
      true
    end

    def last_post_at
      last_post.try(:published_at)
    end

    def last_published_at
      published_posts.first ? published_posts.first.published_at : nil
    end
{'fraction_non_alphanumeric': 0.10266406757634827, 'fraction_numerical': 0.0, 'mean_word_length': 2.9086294416243654, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '332311', 'n_tokens_mistral': 507, 'n_tokens_neox': 497, 'n_words': 111}