Closed (fixed)
Project:
Node Gallery
Version:
6.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
22 Jul 2011 at 18:06 UTC
Updated:
19 Aug 2011 at 13:31 UTC
Jump to comment: Most recent file
Comments
Comment #1
justintime commentedI would, but let's define what would need addressed:
1) views integration. This would actually be easier with the count stored in the db, but we'd have to pull the current implementation out.
2) hook_update_N() implementation to pre-populate the db
3) Define what the count represents - is it the number of Published images, or total images? Currently we do the former by default, but it's user-configurable by editing the sort view.
I don't think it would be too hard, because we already have extrapolated the code for counting into atomic helper functions.
All that being said, I think it may be easier to simply extend the current implementation of node_gallery_views_handler_image_count to be used in sorts and filters. There, we're using drupal's db cache and static caches to store the lists of images, and no matter how fast the db is, you can't outrun a count($array) :)
Thoughts?
Comment #2
crea commented1 and 2 are clear points.
3 can be configurable. Making it configurable shouldn't be hard.
Overall I think I need to inspect the code more closely.
Comment #3
crea commentedOn choosing between counted published/all: I'm going with both. User will be able to select which one to use by choosing proper field.
Comment #4
crea commentedBtw, gallery comment count and image updated date are good candidates for storing in DB. Someone may want to sort by these values, like to show "most commented galleries" and "recently updated galleries" lists.
But converting them into DB columns is out of the scope of this patch :)
Comment #5
crea commentedTricky part is postponing counting for mass operations. It doesn't make sense to count after each image if you are going to upload/update 100 images in a batch. But then, if the operation breaks in the process, we get broken counts.
I think I will update after each image - it shouldn't be that slow to count gallery images. We are not talking about counting all images on the server.
Comment #6
crea commentedDo we need
node_gallery_views_handler_image_countat all, besides displaying image count in views ? I'm going to remove it. Counting will not need special handlers - default ones from Views will do.Comment #7
crea commentedI've decided not to use cached list of gallery nids for several reasons:
1) It's not useful in mass operations when cache is being cleared many times
2) we still need to count nodes in the database directly, when cache is missing
3) We don't have a function to count all (including unpublished) nodes (using a cached list), and I wanted to implement consistent approach. Implementing the function seems to be not very useful.
4) Counting single gallery images should be very fast operation even in InnoDB, assuming using of indexes. We also enjoy DB query cache in many cases, such as mass operations.
5) We can always implement some caching later, but we shouldn't resort to premature optimizations. I assume counting in the database has no penalty because it happens only during updates.
Comment #8
crea commentedPatch attached
Comment #9
justintime commentedThis looks really solid -- nice work. Just a few points:
We should do one query here that gets the nid and the status. Then we can iterate over the results incrementing both counters if it's published, but only $all if it's not.
This won't save a lot on one image, but if I update a large set of images, it could save a lot of queries.
To save changing schema definitions in two spots later, you should call node_gallery_schema() and pull your field definitions from that.
Same here - use node_gallery_schema to get your index definitions.
Same here as above, let's query once, and iterate over the results and increment the counters. Some users have a lot of galleries on crappy webhosts with slow MySQL db's.
t('The total number of published and unpublished images in the gallery.')
If we could get these fixes in, I'd love for one community member to test this before I commit, but if everyone's busy I'll see if I can get some time. I'm headed out of town for some family time and won't be back until middle of the week next week.
Comment #10
crea commentedUsing hook_schema in hook_update_N is bad practice. Also, why waste time on removing lines if I already spent it on writing them ?
Comment #11
justintime commentedAlso, why waste time on removing lines if I already spent it on writing them ?
Umm, because of DRY? However, thanks for the reference, I didn't know that about hook_schema().
Also, if you could run that patch through coder module, you'll see a bunch of whitespace issues. If you can fix those now it'll save me time fixing them before the 3.0 release.
Comment #12
crea commentedFunny thing is that reference doc is perfect example of why someone shouldn't use DRY to the extreme :)
On counting using single query: I rewrote it to count in DB. I think it's much better..
I've also fixed whitespace issues and changed that field description string as you asked.
Comment #13
crea commentedSince you released 3.0 without this feature, I can move it into a separate module.
Comment #14
justintime commentedThat's up to you, but I think this does belong in "core" NG. I just didn't want to drop in an untested feature right at the 3.0 release, and I didn't have the time to test it myself. With 3.0 out of the way, if you can re-roll the patch against HEAD (doesn't apply cleanly anymore), I'll commit it in so we can get some testers that way.
Comment #15
dddave commentedI agree that this should go into core. Good milestone for the next dev cicle for the D6 branch.
Comment #16
crea commentedComment #17
justintime commentedCommitted to 6.x-3.x-dev.