-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore using node.views for unique impressions count #5248
Conversation
This should improve performance of various page loads, as it avoids running COUNT() queries on the impressions table, and instead uses the views value, which the impressions gem keeps up-to-date.
8a64cab
to
828f8df
Compare
@publiclab/reviewers please review. @jywarren I saw you were involved in the early adoption of the impressions gem, I'm curious what your take on this is. |
Generated by 🚫 Danger |
I actually just realized there's a caveat with this fix. In order to fix this, along with applying this change, a migration is needed: the I'm not sure exactly what the procedure is in PublicLab for these kind of changes, but I'm happy to pair with someone to get this done. Here's what can be run from rails console in order to update all nodes: Node.ids.each do |id|
node = Node.find(id)
node.update_columns(views: node.impressionist_count(filter: :ip_address))
end |
Hi @alonpeer ! Thank you so much; we could roll a migration into this PR if you think that makes sense? I think we are not /super/ worried about unique vs. non-unique, as this metric is just for getting a general idea anyways -- for a while, bots were triggering it. So, as long as we make a reasonable call, i think we can be OK with it. Thanks so much! |
@jywarren how many rows are there in |
I actually see other migrations written recently, which seem to do similar amount of work, so I assume that it's just fine 😃 |
Maybe run it only for nodes with status=1? But yeah, good call! Thanks!!
…On Mon, Mar 25, 2019 at 6:13 PM alonpeer ***@***.***> wrote:
I actually see other migrations written recently, which seem to do similar
amount of work, so I assume that it's just fine 😃
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5248 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJyzoi4qDqcITXJCxpWj85hYqKijPks5vaUnTgaJpZM4cFrzY>
.
|
Hmm, can't nodes with |
Anyway, migration file added. |
a5cd00b
to
b0c9a49
Compare
Removed the [DO NOT MERGE] instruction 😄 |
Hey @alonpeer, I think you need to regenerate timestamp by running migration again as someone else has changed the file before you. |
You can also manually forward-date it and it should work :-) Thank you!
…On Sun, Mar 31, 2019 at 4:39 PM Gaurav Sachdeva ***@***.***> wrote:
Hey @alonpeer <https://github.com/alonpeer>, I think you need to
regenerate timestamp by running migration again as someone else has changed
the file before you.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5248 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ3LCgi9eyLhyxwxszPB-pCDqWGytks5vcRzfgaJpZM4cFrzY>
.
|
Fixes #1196
This should improve performance of various page loads, as it avoids
running COUNT() queries on the impressions table, and instead uses the
views value, which the impressions gem keeps up-to-date.
Notice that I update the tests to
.reload
the node before reading values,because ActiveRecord caches those, which is why tests fail without it.
Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!
rake test
@publiclab/reviewers
for help, in a comment belowIf tests do fail, click on the red
X
to learn why by reading the logs.Please be sure you've reviewed our contribution guidelines at https://publiclab.org/contributing-to-public-lab-software
Thanks!