Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+6 votes
493 views
in Q2A Core by

Below is the code from db/recalc.php (I have removed the lines for External Users to make it easier to read). My question is why are the userdata being deleted from userpoints and then added from qa_users data? Points are anyway being recalculated and so what is the issue for letting the userdata in the userpoints be the same as it will be overwritten after recalculation? The issue with the current approach is that if qa_users table is shared, this recalc will copy all the user data from the Network of sites to the current site. Is it safe to remove the delete? 

 qa_db_query_sub(

                'DELETE FROM ^userpoints WHERE userid>=# AND userid<=# AND bonus=0', // delete those with no bonus

                $firstuserid, $lastuserid

        );

        $zeropoints = 'points=0';

        foreach ($qa_userpoints_calculations as $field => $calculation) {

                $zeropoints .= ', ' . $field . '=0';

        }

        qa_db_query_sub(

                'UPDATE ^userpoints SET ' . $zeropoints . ' WHERE userid>=# AND userid<=#', // zero out the rest

                $firstuserid, $lastuserid

        );

                qa_db_query_sub(

                        'INSERT IGNORE INTO ^userpoints (userid) SELECT DISTINCT userid FROM ^users WHERE userid>=# AND userid<=#',

                        $firstuserid, $lastuserid

                );

        }

Q2A version: 1.8
by
Still awaiting for an answer :)

1 Answer

+1 vote
by
selected by
 
Best answer

Your comments make a lot of sense. The only explanation I can think of is that the recalculation process just didn't contemplate the shared ^users table.

Regarding the delete itself, it can be removed. I guess it is there just to cleanup potentially lost ^userpoints records for users that could have been deleted in the wrong way (removing them from the database directly, which is a classic error people in this site mention they commit).

Even though the delete makes sense, how it is implemented (the split of the no bonus) makes no sense to me. This all can be improved by following this simple algorithm (which really contemplates a shared ^users table):

  1. Remove all user IDs (for the current set) from the ^userpoints table that are not in the ^users table
  2. Recalculate all fields again

For external users, the process should be different but that's out of the scope of the question.

by
Thank you @pupi1985 for confirming. I'll try the change you suggested
...