Permalink
Browse files

aaaaa

  • Loading branch information...
sorah committed Oct 22, 2017
1 parent 4c9f4be commit cebf615bc42a93d5248eee068168487545181caf
Showing with 12 additions and 10 deletions.
  1. +12 −10 isubata/webapp/ruby/app.rb
View
@@ -30,13 +30,11 @@ def since(id, limit: 100)
end
end
require 'singleton'
class AwesomeFetch
STREAM_KEY = 'isubata:stream:message'
STREAM_KEY2 = 'isubata:stream:message2'
def self.instance
@instance ||= AwesomeFetch.new.tap(&:start)
end
include Singleton
def initialize()
@subscribers = {}
@@ -98,6 +96,7 @@ def on_payload(payload)
case payload['type']
when 'message'
p payload
on_message payload
when 'reset'
puts "AwesomeFetch Reset #{$$}"
@@ -106,6 +105,7 @@ def on_payload(payload)
puts "AwesomeFetch Init #{$$}"
reset
on_init
puts "AwesomeFetch Init DONE #{$$}"
end
end
@@ -337,7 +337,7 @@ def user
last_message_id = params[:last_message_id].to_i
bin = AwesomeFetch.instance.channel(channel_id)
res= bin&.since(last_message_id)
res = bin&.since(last_message_id)
unless res
statement = db.prepare('SELECT * FROM message WHERE id > ? AND channel_id = ? ORDER BY id DESC LIMIT 100')
@@ -637,12 +637,7 @@ def db_get_user(user_id)
end
def db_add_message(channel_id, user_id, content)
statement = db.prepare('INSERT INTO message (channel_id, user_id, content, created_at) VALUES (?, ?, ?, ?)')
time = Time.now
messages = statement.execute(channel_id, user_id, content, time)
statement.close
redis.hincrby(redis_key_total_messages, channel_id, 1)
redis.publish(AwesomeFetch::STREAM_KEY,
{
'type' => 'message',
@@ -653,6 +648,13 @@ def db_add_message(channel_id, user_id, content)
'content' => content,
}.to_msgpack
)
statement = db.prepare('INSERT INTO message (channel_id, user_id, content, created_at) VALUES (?, ?, ?, ?)')
messages = statement.execute(channel_id, user_id, content, time)
statement.close
redis.hincrby(redis_key_total_messages, channel_id, 1)
session[:bakusoku] = true
messages
end

0 comments on commit cebf615

Please sign in to comment.