If you remember me, I was one of those who suggested that you pack
polls-js.js a few years ago and make it static. I'm back to bounce off some ideas for version 3, if I may:
1. Combine the queries. Every poll, on every single page load, executes four database calls.
SELECT pollq_active FROM wp_pollsq WHERE pollq_id = 1; SELECT pollip_aid FROM wp_pollsip WHERE pollip_qid = 1 AND pollip_ip = '184.108.40.206'; SELECT pollq_id, pollq_question, pollq_totalvotes, pollq_timestamp, pollq_expiry, pollq_multiple, pollq_totalvoters FROM wp_pollsq WHERE pollq_id = 1 LIMIT 1; SELECT polla_aid, polla_answers, polla_votes FROM wp_pollsa WHERE polla_qid = 1 ORDER BY polla_aid asc;
Isn't four a lot? Could enough hits to a Polls Archive page bring down a server?
2. Create indexes on
wp_pollsip. The column
pollip_ip badly needs it, e.g., the second query above when there are thousands of recorded votes, as it hopefully becomes. Displaying, showing votes and voting will all be slow.
3. On the Logs screen, both unfiltered and filtered, please sort the votes descending by date, not by
pollip_id. It's more interesting and it shows how much is the recent interest in the poll's subject. Sorry, the current sort becomes useless after 100 votes.
4. Sometimes (due to dropped mysql server connections, I think), the vote and voter counts in wp_pollsq and wp_pollsa don't match the votes logged in wp_pollsip. Please have a "Recount" button on one of the admin screens that runs the following script.
## Optimize, for good measure OPTIMIZE TABLE wp_pollsip, wp_pollsq, wp_pollsa; ## Update vote count on questions UPDATE wp_pollsq SET pollq_totalvotes = (SELECT COUNT(*) FROM wp_pollsip WHERE wp_pollsq.pollq_id = wp_pollsip.pollip_qid); ## Update voter count on questions UPDATE wp_pollsq SET pollq_totalvoters = (SELECT COUNT(DISTINCT pollip_ip) FROM wp_pollsip WHERE wp_pollsq.pollq_id = wp_pollsip.pollip_qid); ## Update vote count on answers UPDATE wp_pollsa SET polla_votes = (SELECT COUNT(*) FROM wp_pollsip WHERE wp_pollsa.polla_aid = wp_pollsip.pollip_aid);
4. Bug: When questions or answers are too long, the poll management page simply cuts the text off without warning or notice. Perhaps put a
size limit on the textbox also?
do_action API hook for the "voting" event would be very, very useful. In other words, let a site owner or another plugin author be able to write a third-party function (
add_action) that fires when someone casts a vote. The third party function, for example, might use a Google Analytics'
_trackPageview for further analysis. (Though this suggestion sounds complicated, it quite isn't.)
6. [Nice to Have] Speaking of Analytics, have a Poll Analytics as a dashboard widget: Popular polls this week, Number of votes recorded today, etc. To save on PHP memory, put the code for this on a separate php file that is only
require_onced on admin pages.
7. [For version 3.5??] Surveys. A survey is a group of two or more poll questions (ordered by pollq_id) that share one Vote button. I've begun work on this and can share with you what I've got.