Syosset / syosset

🖥️ The official website of Syosset High School from 2017-2019, powered by Rails 5.
https://web.archive.org/web/20190414065933/https://syosseths.com/
MIT License
9 stars 2 forks source link

Link and announcement indexes query DB a lot #73

Open kailan opened 7 years ago

kailan commented 7 years ago

screen shot 2017-10-15 at 13 43 39

kailan commented 6 years ago

Caused by permission checks querying for the announceable/linkable of each entry.

ghost commented 6 years ago

Is there really all that much that can be done about this without creating security issues around permissions?

kailan commented 6 years ago

@gxrneyme Unfortunately our ORM doesn't support the kind of query we need to be able to fix this, so this is kind of an on-hold issue until it does (or we implement it ourselves).

ghost commented 6 years ago

What were you thinking in terms of queries, @kailan?

kailan commented 6 years ago

@gxrneyme When fetching the announcements/links, we need to add include(:announceable), include(:linkable) to the query to also fetch the place that the announcement/link was posted in. Unfortunately we can't do that, since Mongoid doesn't support the pre-fetching of polymorphic associations.

This could be mitigated for certain views such as departments/activities by only running the permission check once (instead of for each link) since we know that the results are all the same.

ghost commented 6 years ago

@kailan Good thinking on the departments/activities front — would likely speed things up a lot. Will take a look sometime and see if I can put you a PR together.