<commit_before># == Schema Information
# Schema version: 95
#
# Table name: post_redirects
#
#  id                 :integer         not null, primary key
#  token              :text            not null
#  uri                :text            not null
#  post_params_yaml   :text            
#  created_at         :datetime        not null
#  updated_at         :datetime        not null
#  email_token        :text            not null
#  reason_params_yaml :text            
#  user_id            :integer         
#  circumstance       :text            default("normal"), not null
#

# models/post_redirect.rb:
# Saves an HTTP request, so it can be redirected to later.  For example, after
# registering / logging in. This can save POST requests, if post_params_yaml
# is not null.
#
# See check_in_post_redirect in controllers/application.rb for the hack that
# fakes the redirect to include POST parameters in request later.
#
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: <EMAIL>; WWW: http://www.mysociety.org/
#
# $Id: post_redirect.rb,v 1.51 2009-09-17 21:10:05 francis Exp $

require 'openssl' # for random bytes function

class PostRedirect < ActiveRecord::Base
    # Optional, does a login confirm before redirect for use in email links.
    belongs_to :user

    # We store YAML version of POST parameters in the database
    def post_params=(params)
        self.post_params_yaml = params.to_yaml
    end
    def post_params
        if self.post_params_yaml.nil?   
            return {}
        end
        YAML.load(self.post_params_yaml)
    end

    # We store YAML version of textual "reason for redirect" parameters
    def reason_params=(reason_params)
        self.reason_params_yaml = reason_params.to_yaml
    end
    def reason_params
        YAML.load(self.reason_params_yaml)
    end

    # Extract just local path part, without domain or #
    def local_part_uri
        self.uri.match(/^http:\/\/.+?(\/[^#]+)/)
        return $1
    end

    # Makes a random token, suitable for using in URLs e.g confirmation messages.
    def self.generate_random_token
        MySociety::Util.generate_token
    end

    # Make the token 
    def after_initialize
        # The token is used to return you to what you are doing after the login form.
        if not self.token
            self.token = PostRedirect.generate_random_token
        end
        # There is a separate token to use in the URL if we send a confirmation email.
        if not self.email_token
            self.email_token = PostRedirect.generate_random_token
        end
    end

    # Used by (rspec) test code only
    def self.get_last_post_redirect
        # XXX yeuch - no other easy way of getting the token so we can check
        # the redirect URL, as it is by definition opaque to the controller
        # apart from in the place that it redirects to.
        post_redirects = PostRedirect.find_by_sql("select * from post_redirects order by id desc limit 1")
        post_redirects.size.should == 1
        return post_redirects[0]
    end

    # Called from cron job delete-old-things
    def self.delete_old_post_redirects
        PostRedirect.delete_all "updated_at < (now() - interval '6 months')"
    end

end


<commit_msg>Drop post_redirects older than 2 months.  The 6 month limit meant we had far too much redundant data that we were needlessly backing up.<commit_after># == Schema Information
# Schema version: 95
#
# Table name: post_redirects
#
#  id                 :integer         not null, primary key
#  token              :text            not null
#  uri                :text            not null
#  post_params_yaml   :text            
#  created_at         :datetime        not null
#  updated_at         :datetime        not null
#  email_token        :text            not null
#  reason_params_yaml :text            
#  user_id            :integer         
#  circumstance       :text            default("normal"), not null
#

# models/post_redirect.rb:
# Saves an HTTP request, so it can be redirected to later.  For example, after
# registering / logging in. This can save POST requests, if post_params_yaml
# is not null.
#
# See check_in_post_redirect in controllers/application.rb for the hack that
# fakes the redirect to include POST parameters in request later.
#
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: <EMAIL>; WWW: http://www.mysociety.org/
#
# $Id: post_redirect.rb,v 1.51 2009-09-17 21:10:05 francis Exp $

require 'openssl' # for random bytes function

class PostRedirect < ActiveRecord::Base
    # Optional, does a login confirm before redirect for use in email links.
    belongs_to :user

    # We store YAML version of POST parameters in the database
    def post_params=(params)
        self.post_params_yaml = params.to_yaml
    end
    def post_params
        if self.post_params_yaml.nil?   
            return {}
        end
        YAML.load(self.post_params_yaml)
    end

    # We store YAML version of textual "reason for redirect" parameters
    def reason_params=(reason_params)
        self.reason_params_yaml = reason_params.to_yaml
    end
    def reason_params
        YAML.load(self.reason_params_yaml)
    end

    # Extract just local path part, without domain or #
    def local_part_uri
        self.uri.match(/^http:\/\/.+?(\/[^#]+)/)
        return $1
    end

    # Makes a random token, suitable for using in URLs e.g confirmation messages.
    def self.generate_random_token
        MySociety::Util.generate_token
    end

    # Make the token 
    def after_initialize
        # The token is used to return you to what you are doing after the login form.
        if not self.token
            self.token = PostRedirect.generate_random_token
        end
        # There is a separate token to use in the URL if we send a confirmation email.
        if not self.email_token
            self.email_token = PostRedirect.generate_random_token
        end
    end

    # Used by (rspec) test code only
    def self.get_last_post_redirect
        # XXX yeuch - no other easy way of getting the token so we can check
        # the redirect URL, as it is by definition opaque to the controller
        # apart from in the place that it redirects to.
        post_redirects = PostRedirect.find_by_sql("select * from post_redirects order by id desc limit 1")
        post_redirects.size.should == 1
        return post_redirects[0]
    end

    # Called from cron job delete-old-things
    def self.delete_old_post_redirects
        PostRedirect.delete_all "updated_at < (now() - interval '2 months')"
    end

end



{'fraction_non_alphanumeric': 0.0650308595514075, 'fraction_numerical': 0.008730995032364896, 'mean_word_length': 2.3236618309154577, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3486576', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1830, 'n_words': 685}