Performance: fivestar_static() queries for current user's vote even if it's not displayed
Wesley Tanaka - March 22, 2009 - 14:48
| Project: | Fivestar |
| Version: | 6.x-1.15 |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
fivestar_static() unconditionally calls the fivestar_get_votes() function, which in turn runs two SQL queries -- one for the average vote and one for the vote that the currently logged in user gave.
It does this even when the user's vote is not displayed anywhere. This could be optimized by only querying for the logged in user's vote if that information is going to be displayed.

#1
This patch fixes the bug, removing the unnecessary SQL query in the case where the user's vote is not displayed
#2
Please delete this one
#3
The first patch did not work as advertised. This one should.
#4
This patch still isn't quite right because the "dual" display needs the user rating. It looks like this code could be shortened up a bit, since the *only* situation where the user's rating is not needed is if the the display is "average" only.
#5
Rerolled the patch against 1.15 and incorporated quicksketch's suggestion in comment #4
#6
Heh, well there's *still* one use-case that this breaks. The user's vote is still necessary if using any of the display texts except "none" and "average". I rerolled and applied the attached patch, which should satisfy the performance improvement you were hoping for.
#7
Updated patch for the 2.x version. Both versions committed.
#8
Automatically closed -- issue fixed for 2 weeks with no activity.