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

I have found a ton more spam users in my database. They are all with the email ending @sina.com, so other people here might want to check their databases. Anyway there are over 200 of these things, all have zero points and have done nothing on the site. (I am about to block that email from registering.)

I want to quickly delete them all but finding each username, opening the link on the site, and deleting them there will take FOREVER. So I want to know, which tables need the accounts deleted from? And is there an order I need to do things in?

Assume that I have a list of IDs so I can run queries like:

DELETE FROM qa_users WHERE userid IN (12345, 12346, 12347, ...)

 

Q2A version: 1.6

2 Answers

+1 vote
by
selected by
 
Best answer
The general principle for anything like this is that it will be fine, but you will need to click some of the 'recalculate' buttons in the 'Stats' page of the admin panel afterwards, to sort out any denormalized/cached data in the database. There are lots of ON DELETE CASCADE rules in the database that take care of deleting related information.
by
Thanks, this seemed to work a treat.
0 votes
by

I would prefer to use qa_db_user_delete($userid) (located in qa-db-users.php #63)

So if you get all user ids by email and run foreach using the function that may works since it will delete all data from the user.

Edit:

right below above function there is a function qa_db_user_find_by_email($email) which may helps you to find user by email

by
Running that once for each user (i.e. 200+ times) is a huge amount of queries, whereas using WHERE...IN is much quicker. But thanks for the pointer to the function, I can probably just use the same queries from there.
by
Yeah, using the same query could be a good idea..please let me know the approach so I also may can refer in case of need.
...