[2.0.11] Auto Lock MOD

The cleanup is complete. This forum is now read only.

Rating:

Excellent!
3
43%
Very Good
2
29%
Good
1
14%
Fair
0
No votes
Poor
1
14%
 
Total votes: 7

King Moonraiser
Registered User
Posts: 50
Joined: Wed Jun 15, 2005 8:31 pm
Contact:

Post by King Moonraiser »

Would it be possible to run the auto_lock.php manually through a cron job?

Phade
Registered User
Posts: 6
Joined: Fri May 24, 2002 11:37 pm
Location: In a van down by the river...
Contact:

Possible Bug

Post by Phade »

Hey,

I have downloaded and installed auto-lock and it seems to work fine. I was browsing the code to see how it works and found a possible bug in auto-lock.php. Should this line:
auto-lock.php wrote: return array ('topics' => $pruned_topics);


be this instead:
Possible Correction wrote: return array ('topics' => $locked_topics);


Just checking. Thanks again and have a great day!

Phade.
If I had a sig, it would be here...

Phade
Registered User
Posts: 6
Joined: Fri May 24, 2002 11:37 pm
Location: In a van down by the river...
Contact:

Post by Phade »

Hey All,

After further investigation, I have noticed that the plugin works very slowly as written for large data sets (we have 580,000+ posts). I have narrowed it down to the select statement using the OR starting on line 40:

Code: Select all

$sql = "SELECT t.topic_id 
	FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
	WHERE t.forum_id = $forum_id
		$lock_all 
		AND ( p.post_id = t.topic_last_post_id 
			OR t.topic_last_post_id = 0 )";
if ( $lock_date != '' )
{
	$sql .= " AND p.post_time < $lock_date";
}
For some reason, this resulting query is very expensive to calculate. I benchmarked each portion of the OR parts in seperate queries vs. the query as a whole with the OR. The parts executed in miliseconds while the OR executed in minutes.

I have found that by removing the OR and exeuting the two parts seperatly, the query runs much much faster. Here is the same query using a UNION:

Code: Select all

$sql = "SELECT t.topic_id 
	FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
	WHERE t.forum_id = $forum_id
		$lock_all 
		AND  p.post_id = t.topic_last_post_id" .
	( $lock_date != '' ? " AND p.post_time < $lock_date" : '' ) .
	" UNION
	SELECT t.topic_id 
		FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
		WHERE t.forum_id = $forum_id
			$lock_all 
			AND t.topic_last_post_id = 0" .
	( $lock_date != '' ? " AND p.post_time < $lock_date" : '' );
Using UNION requires MySQL 4+. If you must use MySQL 3.x, the query can be split into two execution stages:

Code: Select all

$sql = "SELECT t.topic_id 
	FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
	WHERE t.forum_id = $forum_id
		$lock_all 
		AND t.topic_last_post_id = 0 ";
if ( $lock_date != '' )
{
	$sql .= " AND p.post_time < $lock_date";
}

if ( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, 'Could not obtain lists of topics to lock', '', __LINE__, __FILE__, $sql);
}

$sql_topics = '';
while( $row = $db->sql_fetchrow($result) )
{
	$sql_topics .= ( ( $sql_topics != '' ) ? ', ' : '' ) . $row['topic_id'];
}
$db->sql_freeresult($result);

$sql = "SELECT t.topic_id 
	FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
	WHERE t.forum_id = $forum_id
		$lock_all 
		AND p.post_id = t.topic_last_post_id ";
if ( $lock_date != '' )
{
	$sql .= " AND p.post_time < $lock_date";
}

if ( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, 'Could not obtain lists of topics to lock', '', __LINE__, __FILE__, $sql);
}

while( $row = $db->sql_fetchrow($result) )
{
	$sql_topics .= ( ( $sql_topics != '' ) ? ', ' : '' ) . $row['topic_id'];
}
$db->sql_freeresult($result);
I hope this helps.

Phade.
If I had a sig, it would be here...

qqq123
Registered User
Posts: 15
Joined: Sun Sep 04, 2005 9:32 pm
Location: Vancouver, Canada

Auto-lock Hours

Post by qqq123 »

Can you have the topics auto-lock if now replies within x hours instead of days? Also, can you have it check for locked topics every hour instead of once per day?

guspasho
Registered User
Posts: 45
Joined: Thu Sep 15, 2005 9:25 pm
Location: Portland, OR
Contact:

Post by guspasho »

I am impressed. Fortunately I have a small board (1782 topics) so the "OR" deal isn't an issue for me. However, I have the same problem as one other person: it doesn't lock topics with polls. How can I fix that?
Portland's Anime Convention, Labor Day weekend, http://www.kumoricon.com

User avatar
Jackanape
Registered User
Posts: 1076
Joined: Wed Oct 13, 2004 6:01 am
Location: Capitol of the Great State of New York
Name: Jack Drury
Contact:

Post by Jackanape »

This mod works extremely well for me, and has for some time now...I just upgraded to .18, and it still is a workhorse. Is there an upgrade in store, or should it be OK the way it is?
~Extending the rule of meticulous exactitude to exaspirating punctillio...still.~
Treat your phpBB like a member of the family--Update and MOD her by hand, with HTML-Kit
: : Wanna Talk Poker? : : Image : :

bluesomething
Registered User
Posts: 2
Joined: Wed Dec 03, 2003 9:43 am
Contact:

Post by bluesomething »

i've installed the mod. Everything looks fine, but when I set the enable forum autolocking to yes in the admin panel configuration and then click ok, it will be reset to no.

anyone know how i solve this?


never mind, one of the queries didn't work, i've fixed it already
Last edited by bluesomething on Fri Apr 14, 2006 1:15 pm, edited 1 time in total.

User avatar
Jackanape
Registered User
Posts: 1076
Joined: Wed Oct 13, 2004 6:01 am
Location: Capitol of the Great State of New York
Name: Jack Drury
Contact:

Post by Jackanape »

bluesomething wrote: i've installed the mod. Everything looks fine, but when I set the enable forum autolocking to yes in the admin panel configuration and then click ok, it will be reset to no.

anyone know how i solve this?


Did you run your SQL queries? Those are usually the culprit in something like this.
~Extending the rule of meticulous exactitude to exaspirating punctillio...still.~
Treat your phpBB like a member of the family--Update and MOD her by hand, with HTML-Kit
: : Wanna Talk Poker? : : Image : :

Masochist
Registered User
Posts: 2
Joined: Wed Mar 29, 2006 7:31 am
Location: Jordan
Contact:

Is it possible to do a time lock also ?

Post by Masochist »

Great Job

This might be my first post in here, I am using phpBB v 2 and Guys I really would like to thank you for the very effort you are doing. I bought a domain name and a host and installed the whole forum. everything is working just great and more than I imagined.

I have only one problem which is really interesting to be posted. I work for an Architecture Company in Jordan. I and the rest of the team members gathered and got the permission for the high-level management in our firm to have an internal/external forum for our employees and our boss was very happy though we paid the cost ... but he had one comment on those who are abusing the working hours on the forum so he asked me to do something like a restriction. He wanted the Forum to be disable during the working hours except the break.

I know I can disable the forum from the configuration but this will be no professional to have it disabled manually every day and in hours. So I am asking you guys of there's any way to amend the script to make it AUTOMATICALLY disabled during the working hours.

Thank you,
Nida' Elias


Amman - jordan
www.2k-forum.com

dcrhaekte
Registered User
Posts: 5
Joined: Tue Jul 18, 2006 2:43 pm

Post by dcrhaekte »

I have installed this mod sucessfully but when I went back to my admin control panel I got this error on the left side where the controls are supposed to be:

Code: Select all

Parse error: parse error, unexpected T_STRING in /var/www/asgard/admin/admin_forums.php on line 506
The section it is referring to is this:

Code: Select all

505: $sql = "UPDATE " . FORUMS_TABLE . "
				SET forum_name = '" . str_replace("\'", "''", $HTTP_POST_VARS['forumname']) . "', cat_id = " . intval($HTTP_POST_VARS[POST_CAT_URL]) . ", forum_desc = '" . str_replace("\'", "''", $HTTP_POST_VARS['forumdesc']) . "', forum_status = " . intval($HTTP_POST_VARS['forumstatus']) . ", forum_view_threshold = " . intval($HTTP_POST_VARS['forumviewthreshold']) . ", prune_enable = " . intval($HTTP_POST_VARS['prune_enable']) . ", auto_lock_enable = " . intval($HTTP_POST_VARS['auto_lock_enable'])
				506: WHERE forum_id = " . intval($HTTP_POST_VARS[POST_FORUM_URL])
The original pre mod change looked like this:

Code: Select all

505: $sql = "UPDATE " . FORUMS_TABLE . "
				SET forum_name = '" . str_replace("\'", "''", $HTTP_POST_VARS['forumname']) . "', cat_id = " . intval($HTTP_POST_VARS[POST_CAT_URL]) . ", forum_desc = '" . str_replace("\'", "''", $HTTP_POST_VARS['forumdesc']) . "', forum_status = " . intval($HTTP_POST_VARS['forumstatus']) . ", forum_view_threshold = " . intval($HTTP_POST_VARS['forumviewthreshold']) . ", prune_enable = " . intval($HTTP_POST_VARS['prune_enable']) . "
				506: WHERE forum_id = " . intval($HTTP_POST_VARS[POST_FORUM_URL])
Does anyone see why I am getting that error with the new syntax? I've racked my brains on this for 3 days now and I'm at the point where I either fix this or wipe the entire forum. What good is a PHPBB if you cannot do anything in the admin control panel? Ugh!

Any help will be greatly appreciated.

dcrhaekte
Registered User
Posts: 5
Joined: Tue Jul 18, 2006 2:43 pm

Post by dcrhaekte »

Anybody?

qqq123
Registered User
Posts: 15
Joined: Sun Sep 04, 2005 9:32 pm
Location: Vancouver, Canada

Post by qqq123 »

Can you use autolock to lock topics that haven't had activity for hours or minuted instead of days?

janlotte
Registered User
Posts: 2
Joined: Sat Sep 30, 2006 7:09 am
Contact:

Post by janlotte »

Hi all,

Phade noticed a possible bug and offered a possible solutions to the max_user_connections errors on large forums.
Is it a bug and is his solution working with UNION? Is it safe to use? I heard UNION can cause problems. I emailed both Sune and phade but both did not answer my email. So I hope someone can check this solution cause Sune's last post was Wed Jan 05, 2005 and Phade's last post was Sun Jul 17, 2005 given the fact they did not answer my email and both dates I doubt they will check this post.

Hope someone can help me out cause this mod would be a great addition to my forum.

With kind regards,
Lotte

Post Reply

Return to “[2.0.x] MOD Database Cleanup”