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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wesley Tanaka’s picture

FileSize
2.13 KB

This patch fixes the bug, removing the unnecessary SQL query in the case where the user's vote is not displayed

Wesley Tanaka’s picture

FileSize
2.55 KB

Please delete this one

Wesley Tanaka’s picture

FileSize
2.41 KB

The first patch did not work as advertised. This one should.

quicksketch’s picture

Status: Active » Needs work

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.

Wesley Tanaka’s picture

Version: 6.x-1.13 » 6.x-1.15
Status: Needs work » Needs review
FileSize
1.72 KB

Rerolled the patch against 1.15 and incorporated quicksketch's suggestion in comment #4

quicksketch’s picture

Category: bug » task
Status: Needs review » Needs work
FileSize
1.63 KB

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.

quicksketch’s picture

Status: Needs work » Fixed
FileSize
1.65 KB

Updated patch for the 2.x version. Both versions committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.