Performance problem when returning json with rabl after query with activerecord

Asked

Viewed 67 times

0

I’m having trouble adjusting performance when returning json after a database query.

I’ve tried a lot of things, and I’m not getting any faster.

Someone can give me a boost with this ?

This is the query in the controller controller

Method in the model model work

Rabl show rabl

  • Hello prefer to post your code in text instead of copy and paste a print of it.

1 answer

0

As recommended by Carvalho paste your code into text. It will be much simpler to help you and you will get help easier and faster if you do it the right way.

/editing-help#code

About your code. One of the things I’m fixing is that you’re using SQL to scan the entire table and then handle it. Try to minimize bank efforts in the array.

Come on, I’d trade these methods for this

def students
  works_students.where.not(student: nil)
end

If you have used this same concept of Students in other models for sure your performance problem will be there. However, if it is only this, then there are probably more items to be analyzed.

def program_id
  Qrcode.find_by(code: self.teacher_qrcode).try(:program_id)
end

I don’t know about the rest. I’d have to take a closer look at your implementation.

I do not know better to create an association of has_one :qrcode in the model Teacher?

Having an association you could directly access the code by the controller so:

work.teacher.qrcode.program_id

Browser other questions tagged

You are not signed in. Login or sign up in order to post.