Support Forum

Prune Database Request

MY My
My
Member

I’ve just installed the prune database plugin so I can reduce the size of my very large database but I think there’s a serious oversight with the plugin, there should be an option to prune topics based on last reply date rather than creation date. Some topics, while they were created a long time ago are still active, and while you have the option to go through and select certain topics from a filtered list, there’s no easy way to see the date of the last post to see which topics are still (or recently) active.  Any chance this can be altered soon? It seems (to someone who doesn’t really know) it shouldn’t be too hard to create an extra option to select by last reply date instead of topic creation date… ?

31 Answers

New Answer

YS Yellow Swordfish
Yellow Swordfish
Member

That’s a really very good point.
I will open a ticket right away to see about changing it

MY My
My
Member

Aside from that request… it seems like nothing happens when I prune anyway… any reasons people know of it wouldn’t actually do anything even after it pops up a message saying it’s been pruned?

YS Yellow Swordfish
Yellow Swordfish
Member

Offhand no. It appears to be working on my test sites just fine as I literally just tried it.
You do need to be judicious and not throw huge numbers at it in one go which is something we do have logged to address one day. To be honest this might be the first time it has ever been mentioned in a support question! Which means it tens to fall off the edge as far as priority goes.

But try it in small numbers – I just pruned about 180 topics with no problem – and, as I say, it works fine this end. Could it be that it did some of the work but not all that you asked it to?

MY My
My
Member

I was just coming back to report it works on a smaller number of topics. I guess I should just wait and hope and update is out soon so I can be more selective about what I want to delete anyway.

I’ve been running SP since 2008 so there’s a lot of old posts to prune, but my database is about 490mb now so it’s time! I made a copy of the forums on another server so I can keep an archive for our users who hate the idea of losing any old posts at all.

YS Yellow Swordfish
Yellow Swordfish
Member

Yes I had already stated on the ticket that we need to also find a way to force the removals to be in small batches in some way…

MP Mr Papa
Mr Papa
Member

the number that can be removed is going to be server dependent… before it exhausts resources… I works on my big server, but we do need to cater to the lower common denominator…

MY My
My
Member

Are you able to provide any idea of timeline for this alteration? Are we talking days, weeks or months? I need to make a decision about whether or not I should fumble my way through as is or try and wait for an update

YS Yellow Swordfish
Yellow Swordfish
Member

I will attempt to look some time today at the query to see if the last post date can be used instead of the topic start date. That bis the easy bit and I might even be able to give you a code change.

Batching and requesting smaller numbers for the server to work on at any one time is a far, far bigger task I am afraid.

YS Yellow Swordfish
Yellow Swordfish
Member

It’s hard for me to test but I think I have this right! The following change will alter the listing based on the last post in a topic instead of the first as you suggest and which I agree is better…

You will need to edit two files:

(1) wp-content/sp-resources/forum-plugins/prune-db/admin/sp-prune-db-admin-prune.php

Quite near the top you will find this code:

$sql = "SELECT * FROM ".SFTOPICS.
" WHERE topic_date <= '".$date."'".$forum_id.
" ORDER BY topic_date, forum_id ASC";

Change it for the following code:

$sql = "SELECT * FROM ".SFTOPICS."
JOIN ".SFPOSTS." ON ".SFTOPICS.".post_id = ".SFPOSTS.".post_id
WHERE ".SFPOSTS.".post_date <= '".$date."'".$forum_id.
" ORDER BY ".SFPOSTS.".post_date, ".SFTOPICS.".forum_id ASC";

which should then display a corrected topic listing. It would be wise to actually just test this against known data to ensure it is correct but I believe it to be so.

(2) wp-content/sp-resources/forum-plugins/prune-db/library/sp-prune-db-components.php

At line 69 you will find this block of code:

if ($first) {
    $forum_ids = ' AND (forum_id='.sp_esc_int($_POST['group'.$x.'forum'.$y]);
    $first = false;
 } else {
    $forum_ids .= ' OR forum_id='.sp_esc_int($_POST['group'.$x.'forum'.$y]);
 }

change it to:

if ($first) {
    $forum_ids = ' AND ('.SFTOPICS.'.forum_id='.sp_esc_int($_POST['group'.$x.'forum'.$y]);
    $first = false;
} else {
    $forum_ids .= ' OR '.SFTOPICS.'.forum_id='.sp_esc_int($_POST['group'.$x.'forum'.$y]);
}

As stated – this does nothing for the batching into smaller chunks. I would suggest no more than, say, 100 topics at a time but this value will differ for everyone.

MY My
My
Member

I still have a problem. I have a couple of unusually large topics that I can’t even prune on their own… any suggestions?

YS Yellow Swordfish
Yellow Swordfish
Member

Wow really?

Are all of your SP components ( core/plugins) all up to date?

And what happens exactly when you try to do this one topic? Have you tried from the front end using the forum tools?

MY My
My
Member

Everything is up to date.

I’m not seeing any options to do it from the front end…

MY My
My
Member

my brain is dumb LOL… there’s that whole “delete” thing right!? LOL

Nope, looks like I can’t delete from the front end either.

… the longest topic has 10620 posts eek