Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
213 views
in Q2A Core by
reshown by

I'd like to have the total votes of the entire q2a forum as cache value via qa_opt() available.

Seems that this is not yet implemented in the core. Would be nice to have it.

Because this enables us to e.g. write a plugin to show in the user profile "Top x % this year" (based on the votes).

I guess the workaround for now is:

1. setup my own opt value, e.g. "total_votes"

2. have an event listener and add +1 for each incoming vote

3. read the value in the userprofile plugin via qa_opt("total_votes")

Q2A version: 1.8.0
by
In here https://github.com/q2a/question2answer/issues/574, an issue you've updated a few hours ago, you are saying that the core takes too much time to process a vote. In this question you are requesting the core to do more things while processing a vote. So you're requesting the core to do more things in less time. That's just not possible not only in software but I'd rather say in life :)

2 Answers

0 votes
by

I guess you can simply get total number of votes defined a function like this:

function custom_get_total_votes() {

$totalvotes = qa_db_read_one_value(qa_db_query_sub(

"SELECT SUM(ABS(vote)) FROM ^uservotes",

), true);

return $totalvotes;

}

 

by
Note this query performs a full scan and is a performance killer
by
if this function is run only once when vote event is performed, and stored somewhere, it will not have many affect on performance. The function is just a guide for @q2apro.
An I also agree that it should be pluginarized, not implemented on core.
0 votes
by

I don't really agree that it would be "nice to have". The more you add to the core, the slower it gets. So the core should be kept minimal.

You mention this:

Because this enables us to e.g. write a plugin to show in the user profile "Top x % this year" (based on the votes).

Two comments derive from that one. On one hand, that "top x" is very specific to your needs. Other sites won't even care at all about user rankings or even consider "top x" applying a different algorithm, as the implict ranking displayed in the user profile, for example. On the other hand, having that in the core does not "enable us" to do that. You can totally do that with a plugin. No need for that to be in the core. If something can be pluginized, it should.

Regarding the steps you mention, they are the most efficient ones. Make sure you use a better naming approach than "total_votes", as I mentioned here https://www.question2answer.org/qa/31654

...