Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
in Plugins by
edited by

former question title: How to remove events that are related to deleted questions/answers

I am using the History plugin that displays user activity and points a user receives.

Sometimes questions get deleted, then the related events are still in the listing. Using >Admin >Stats >Recount/Reindex... has no effect on the events.

How can I remove/clean obsolete events that are related to deleted, no-more-excisting questions... not manually... thanks!

Is there any function/plugin that can do this (btw, I know that the data is saved in table qa_eventlog).


One example entry in table qa_eventlog: The event is set as "in_a_select", under params it is showing a string that holds the "parentid=1700", but question 1700 does not exist anymore -> I could use table qa_posts / column postid to detect if the question exists (for the example: 1700 is missing)...

If I understand correctly, this is a problem specifically in the history plugin. The reason is that it's not cross-checking against the posts table with a JOIN. See qa_db_user_updates_selectspec(...) in qa-db-selects.php for the type of thing.
mhhh... yes and no.

You could say, why does an event in the qa_eventlog exist if the event's source does not exist anymore.

On the other hand, we could agree, that qa_eventlog logs everything (which is actually true, from creating the question to answers to deleting it), then the history plugin has to be modified.

I think now, you are right, it should be the history plugin. thanks gid!

1 Answer

0 votes
selected by
Best answer
I don't see that events related to deleted questions should be deleted.  The events happened, didn't they?  The history plugin shows even delete events themselves.

I can make the join request and filter out events for deleted posts, but I don't see a reason to personally.

This idea makes me think of 1984 :)
1984 :) no, the actual reason is that the history plugin shows (which is great) the assigned points for asking a question and answers + best-answer.

All my users have their 30-day-history. However, when I delete a question they still see "you answered:  |   { empty }   |   7 points" ... but they got no 7 points!

Of course, we could track 'deleted questions' and show an event in the history, such as "you lost 7 points because answer & question were deleted". But I am quite sure that this is worse. Better go for not showing these events.

This is why I asked for fixing this "bug".

PS: If you don't like this approach, where/how do I have to change the plugin code to achieve this?
But you see, they did get seven points.  They lost them again because the post was deleted, but that doesn't make the event wrong.  It's not a reflection of how many points they have, just how many they got (or lost) for each event.  It actually would be useful to track incoming deletes as well, but I think that's too complicated.

I can push a new version of the plugin that has a LEFT JOIN to check for the postid in ^posts.  Then you can just do a check to see if the 'postid' index is null and tell it to skip that one.  I'll put that in the code commented and you can just uncomment it if you like.
that would be awesome! Thanks a lot.
okay, pushed now.  check the event loop in qa-history-layer.php
wonderful, quick and easy!

To keep badges showing up, I changed:
if(!in_array($type, $nopost) && $event['postid'] == null)

if(!in_array($type, $nopost) && $event['postid'] == null && $type!='badge_awarded')

great plugin, thanks a 1000!