Problem of perfomance when returning json with rabl after consultation with activerecord

0

I'm having trouble adjusting performance by returning json after a query to the database.

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

Can anyone give me strength with this?

This is the query in the controller

Methodnotmodel

Rabl

    
asked by anonymous 29.06.2016 / 21:06

1 answer

0

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

link

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

Come on, I would trade these methods for it

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

If you have this same concept of students in other models, your performance problem will surely 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 do not know about the rest. I'd have to take a closer look at your implementation.

I do not know how to create an association of has_one :qrcode in model teacher?

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

work.teacher.qrcode.program_id
    
02.08.2016 / 10:21