Zulhilmi Zainudin

Joined

280 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in Realtime SSH Logs with ActionCable Discussion

I'm very excited to learn more about Socket. 🙂
Nice one Chris. Question about the `variant` and `preview`. Does the thumbnails will get saved into the disk or they happen on the fly? That's expensive if we do it on the fly, right? Thanks.

Chris, what if my current API code base doesn't really in RESTful shape? Does AMS still can help?

Example of my current routes:

1. /transaction_history.json (I don't have TransactionHistory model)
2. /buy.json (I don't have Buy model)
3. /user_status.json (mixed data between User model and several other models)

I'm not using AMS now. Still using render :json => {} approach inside my API controller.

Thanks.

Posted in Comments With Polymorphic Associations Discussion

Thank you Chris!

Thanks Chris for this video.

Would you mind to cover how to upload images to SimpleMDE like in WordPress editor?

Example:

Browse photo(s) -> the photo(s) get displayed directly on the text editor.

Thank you!

Example screenshot:
http://cdn4.wpbeginner.com/...

Thanks Chris. Questions:

1. Does Searchkick auto reindex questions after new question is created?

2. If number 1 is no, what's the best way to make it happen? A callback inside the Question model?

3. You did mentioned earlier inside the video where Searchkick has a 'smart feature' where it can rank the result based on the popularity. Does it available out of the box or extra configuration required?

Thanks.

Posted in [Performance] - Can I Still Refactor This Code?

Got it. I'll give it a try!

Posted in [Performance] - Can I Still Refactor This Code?

Thanks Chris. What do you mean by in place mutation methods improve performance?

Can you elaborate more and give some examples?

Thanks.

Posted in Shrine Backgrounding and Video Transcoding Discussion

Noted Chris. Thanks!

Posted in [Performance] - Can I Still Refactor This Code?

I'm building an API based Rails app and I've one endpoint to list down all active users account numbers and gold balance inside that account.

The requirement is:

  1. Take all active users (kyc_passed: true) and not admin users (admin: false)
  2. For each user, take his/her gold balance amount and trucate
  3. Sort by account number (ascending)

I delegate and put all the logics inside User model. But I found this query still using lots of objects. AppSignal report for 1500+ users:

As you can see above, 66K objects were allocated for this sample.

I believe this query can be improved so that less objects are allocated for each request. But I'm out of idea already. I try to switch between .includes and .joins but I can't see significant improvements.

And one more thing, I didn't have luck with .select. That's why I'm using .pluck.

Please advice how can I improve this query. I truly appreciate your help.

Models / table columns:

All non-relevant columns were omitted for readability.

class User < ActiveRecord::Base {
  :id             => :integer,
  :admin          => :boolean,
  :kyc_passed     => :boolean,
  :account_number => :string
}

class Balance < ActiveRecord::Base {
  :id             => :integer,
  :user_id        => :integer,
  :gateway_id     => :integer,
  :amount         => :decimal
}

class Gateway < ActiveRecord::Base {
  :id             => :integer,
  :currency       => :string
}

Example result:

{
   "result":"ok",
   "data":[
      {
         "account_number":"45800000001",
         "gold_balance":10.132
      },
      {
         "account_number":"45800000002",
         "gold_balance":11.753
      }
   ]
}

Code:

#  app/controllers/api_controller.rb
def cust_gold_balances
    data = User.all_users_gold_balances
    render :json => {result: "ok", data: data}
end
#  app/models/user.rb
scope :active_users, -> {where(kyc_passed: true, admin: false)

def self.all_users_gold_balances
    gold_gateway_id = Gateway.find_by(currency: "GLD").id
    user_balances   = Balance.where(gateway_id: gold_gateway_id).includes(:user).where(user: active_users).pluck('balances.amount', 'users.account_number')
    array           = []
    user_balances.each {|balance| array << {account_number: balance[1], gold_balance: balance[0].truncate(3)} }
    return array.sort_by {|hash| hash[:account_number]}
end

Posted in Shrine Backgrounding and Video Transcoding Discussion

Thanks Chris for this. I'm really excited to watch next episode and really can't wait to see how to perform background transcoding using AWS Elastic Transcoder and AWS S3!

For that episode, can you cover using Sidekiq instead of sucker_punch? 😀

Posted in How ActionCable Uses Redis Discussion

Chris, I'm currently using RedisCloud $10 plan on my Heroku app.

From the pricing page (https://elements.heroku.com..., this plan has 256 connections.

Does it mean my app can only serve 256 concurrent (ActionCable chat) users at one time?

What will happen to 257th user? He will not subscribed to Redis Pub/Sub and his message won't get broadcasted?

Posted in Direct File Uploads to S3: Part 3 Discussion

Chris, can you cover how to upload multiple videos to S3 with progress bars (using Shrine direct upload) + AWS transcoding to web & mobile format after the record has been created in database using ActiveJob ie Sidekiq?

Posted in File Uploads in Rails With Shrine Discussion

Really great video. Thanks Chris!

Can you also cover secure upload/file retrieval together with direct upload to S3 and jquery/multi-file/background uploading (with progress bar)?

Posted in Group Chat with ActionCable: Part 3 Discussion

Chris, can you also show how to upload images inside the channel in real-time using ActionCable?

Posted in Group Chat with ActionCable: Part 1 Discussion

Chris, don't forget to validate uniqueness of the username.

Thanks Chris!

Thanks!

@honglilai:disqus @excid3:disqus so, does that mean if we are not specifying either redis or postgresql as adapter, the chat message couldn't be saved into our app database?

Thanks Chris for this great tutorial! I've 2 questions:

1. Can we use this setup on Heroku?

2. Currently, I'm using Puma server on Heroku which only allow 16 concurrent connection at a time https://devcenter.heroku.co...

My question, if we use Passenger, can we get the 'unlimited' concurrent connection?

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.