check last_write_at field when applying rate limits to channels
This commit is contained in:
parent
749b09517c
commit
ca5acacee9
@ -312,7 +312,7 @@ class ChannelsController < ApplicationController
|
|||||||
talkback_key = params[:talkback_key] || false;
|
talkback_key = params[:talkback_key] || false;
|
||||||
|
|
||||||
# rate limit posts if channel is not social and timespan is smaller than the allowed window
|
# rate limit posts if channel is not social and timespan is smaller than the allowed window
|
||||||
render :text => '0' and return if (RATE_LIMIT && !tstream && !talkback_key && !channel.social && Time.now < channel.updated_at + RATE_LIMIT_FREQUENCY.to_i.seconds)
|
render :text => '0' and return if (RATE_LIMIT && !tstream && !talkback_key && !channel.social && channel.last_write_at.present? && Time.now < (channel.last_write_at + RATE_LIMIT_FREQUENCY.to_i.seconds))
|
||||||
|
|
||||||
# if social channel, latitude MUST be present
|
# if social channel, latitude MUST be present
|
||||||
render :text => '0' and return if (channel.social && params[:latitude].blank?)
|
render :text => '0' and return if (channel.social && params[:latitude].blank?)
|
||||||
@ -323,6 +323,8 @@ class ChannelsController < ApplicationController
|
|||||||
feed.entry_id = entry_id
|
feed.entry_id = entry_id
|
||||||
# set user agent
|
# set user agent
|
||||||
channel.user_agent = get_header_value('USER_AGENT')
|
channel.user_agent = get_header_value('USER_AGENT')
|
||||||
|
# set the last write at time
|
||||||
|
channel.last_write_at = Time.now
|
||||||
|
|
||||||
# try to get created_at datetime if appropriate
|
# try to get created_at datetime if appropriate
|
||||||
if params[:created_at].present?
|
if params[:created_at].present?
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
# user_agent :string(255)
|
# user_agent :string(255)
|
||||||
# realtime_io_serial_number :string(36)
|
# realtime_io_serial_number :string(36)
|
||||||
# metadata :text
|
# metadata :text
|
||||||
|
# last_write_at :datetime
|
||||||
#
|
#
|
||||||
|
|
||||||
class Channel < ActiveRecord::Base
|
class Channel < ActiveRecord::Base
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
class AddLastWriteAtToChannels < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :channels, :last_write_at, :datetime
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20141024161555) do
|
ActiveRecord::Schema.define(version: 20150311201046) do
|
||||||
|
|
||||||
create_table "active_admin_comments", force: true do |t|
|
create_table "active_admin_comments", force: true do |t|
|
||||||
t.string "namespace"
|
t.string "namespace"
|
||||||
@ -105,6 +105,7 @@ ActiveRecord::Schema.define(version: 20141024161555) do
|
|||||||
t.string "user_agent"
|
t.string "user_agent"
|
||||||
t.string "realtime_io_serial_number", limit: 36
|
t.string "realtime_io_serial_number", limit: 36
|
||||||
t.text "metadata"
|
t.text "metadata"
|
||||||
|
t.datetime "last_write_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "channels", ["latitude", "longitude"], name: "index_channels_on_latitude_and_longitude", using: :btree
|
add_index "channels", ["latitude", "longitude"], name: "index_channels_on_latitude_and_longitude", using: :btree
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
@ -49,6 +49,7 @@
|
|||||||
# user_agent :string(255)
|
# user_agent :string(255)
|
||||||
# realtime_io_serial_number :string(36)
|
# realtime_io_serial_number :string(36)
|
||||||
# metadata :text
|
# metadata :text
|
||||||
|
# last_write_at :datetime
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
Loading…
Reference in New Issue
Block a user