Needs review
Project:
Favorite Nodes
Version:
5.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
28 Jan 2008 at 20:17 UTC
Updated:
12 Jul 2009 at 18:11 UTC
Jump to comment: Most recent file
Comments
Comment #1
CoolDreamZ commentedSubscribing as I would also like this functionality, especially the second bullet point (sort criteria in a View)
Comment #2
asund commentedI managed to make a list of the most favorited nodes.
I'm sure the code can be improved a lot by someone who actually knows php. :P
It is VERY slow as it is now (at least on my site with loads of content)
Comment #3
costinius commentedSubscribing. I've tried to fix it myself (the 2d point) but failed so far.
Comment #4
costinius commentedHi, I've fixed the 2d problem "Sort criteria to sort by number of users having added the node as a favorite." It works fine for me.
The updated files are attached. You'll have to reinstall the module to make it work (remember to backup {favorite_nodes} table and restore it after the reinstallation of the module).
Shortly, my code creates a new table {favorite_nodes_count} which stores the data with the number of users who added the node as a favorite. Then making it work in views becomes a piece of cake. If anyone wants to add a filter (1st problem), you can easily add necessary code.
Disclaimer: It took me 15 minutes to update the module, so I can't guarantee that it's perfect. Please test it first.
Comment #5
kbahey commentedThanks for this.
However, including a patch will make the review much easier than the full module.
Please read about how to create a patch at http://drupal.org/patch
Comment #6
costinius commentedOoops, found one bug already. Attached is the corrected version.
Khalid, I know I need to read that and post patches instead of full modules, sorry. I'm not that advanced at Drupal yet. Will do my best next time :)
Comment #7
kbahey commentedI am divided about this patch. One one hand, it solves the issue of "Count". But from an architecture point of view, it introduces extra (summary) table, which is denormalization. It solves the problem now, but becomes a management and maintenance burden, and introduces the possibility of inconsistencies later.
So, I like to get some feedback on this from an architecture/design point of view.
Hence, I created a cleaned up patch from costinius' .zip file for those who want to review it.
Comment #8
costinius commentedKhalid, thanks for creating the patch. Just 2 comments:
1. I didn't find a better way how to solve the problem. If anyone has other ideas, please suggest.
2. The patch updates the summary table only when someone adds/removes a node to/from the favorites. Afterwards the views module retrieves the data directly from this table, which makes this operation much faster than calculating the # of users each time a view is loaded in the browser window. It becomes even more relevant when the view is used often by a big number of users.
Comment #9
SpikeX commentedSubscribing.
I need a way to sort by favorite count. I tried to add a Sort views handler to the view API code, but it didn't work right.