Megan-Ralph / tumblr-ish

A tumblr-like app made for fun!
0 stars 0 forks source link

Activity Stream Optimisations #1

Open drobny opened 1 year ago

drobny commented 1 year ago

Hey Megan,

First of all thanks for submitting this for review! I am going to add a few issues to this for you to work on to see where you can get to. Please don't spend too much doing this in your own time / work time as would hate to add anymore work to your most likely busy schedule. Maybe just time box to a couple hours or something.

So first one is the activity stream - at the minute it is a combination of a query and sorting in ruby which can be resource intensive with a large dataset.

As discussed in the interview, is there a way you can optimise this so you only have to do one single query to get all the relevant information for a given user?

Megan-Ralph commented 1 year ago

Hi Rob,

Thank you so much for leaving your feedback and issues!

You can see here (commit link) how I have optimised the activity stream.

As you can see, I have combined the three separate queries for articles, events and comments into one single query using the 'union_all' operator. I have also added the sorting and limiting of the activities into the query which should make it much more efficient!