2

I try to use jsonb data format(new feature in postgresql), to log user(interactive with devise) actives, like pageview...search string...

versions: Rails 4.2.6 Postgresql 9.5

my model:

class CreateUserLogs < ActiveRecord::Migration   
    def self.up
      create_table :user_logs, :id => false do |t|
        t.integer :user_id
        t.jsonb :data, default: '{}'
      end
      add_index :user_logs, :user_id   end   
    def self.down       
      drop_table :user_logs   
    end 
end

my log service object:

class UserLogger

  def initialize(current_user)
    @user_id = current_user.present? ? current_user.id : 0
  end

  def insert_log_data(request_ip, controller_name, action_name, object)
    user_log = UserLog.create!({
      user_id: @user_id,
      data: {
        ip_address: request_ip,
        controller_name: controller_name,
        action_name: action_name,
        id: object.id,
        created_at: Time.now.to_s(:db)
      }
    })
  end
end

My target is simple analyze log data for all user and each one.

to get something like top 3 articles user like...etc. postgresql jsonb is noSQL, a good choice for log data.

I try impressionist gem, but when data grow bigger, the efficacy will fall.

should I put the User_ID in the jsonb data type too? or another better way?(I already use Google Analytics, but it can't track activity by each user. I need customized data.)

But if I want to group and order data, Maybe impressionist is a better choice?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.