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

Wesley Tanaka - March 22, 2009 - 15:36

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

AttachmentSize
410154.patch 2.13 KB

#2

Wesley Tanaka - March 22, 2009 - 15:52

Please delete this one

AttachmentSize
410154.patch 2.55 KB

#3

Wesley Tanaka - March 22, 2009 - 15:52

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

AttachmentSize
410154.patch 2.41 KB

#4

quicksketch - April 29, 2009 - 20:38
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.

#5

Wesley Tanaka - May 1, 2009 - 20:29
Version:6.x-1.13» 6.x-1.15
Status:needs work» needs review

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

AttachmentSize
410154.patch 1.72 KB

#6

quicksketch - July 1, 2009 - 03:00
Category:bug report» task
Status:needs review» needs work

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.

AttachmentSize
fivestar_get_votes_efficiency.patch 1.63 KB

#7

quicksketch - July 1, 2009 - 03:05
Status:needs work» fixed

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

AttachmentSize
fivestar_get_votes_efficiency2.patch 1.65 KB

#8

System Message - July 15, 2009 - 03:10
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.