[erledigt] Zeit jeder einzelnen SQL-Abfrage anzeigen lassen

Fragen zu allen Themen rund ums Programmieren außerhalb von phpBB können hier gestellt werden - auch zu anderen Programmiersprachen oder Software wie Webservern und Editoren.
Benutzeravatar
Gumfuzi
Ehemaliges Teammitglied
Beiträge: 2454
Registriert: 26.03.2004 22:25
Wohnort: Linz, AT
Kontaktdaten:

Beitrag von Gumfuzi »

*gg* darum habe ich Dir ja das geschrieben, denn ich hatte dazumals auch lange nach einer Lösung für das langsame Portal gesucht.

Den Block habe ich drin für die letzten Themen:

Code: Alles auswählen

// die letzten Themen START
$topic_length = '60';	// length of topic title
$topic_limit = '5';	// limit of displayed topics
$special_forums = '0';	// specify forums ('0' = no; '1' = yes)
$forum_ids = '';		// IDs of forums; separate them with a comma

$sql_auth = "SELECT * FROM ". FORUMS_TABLE;
if( !$result_auth = $db->sql_query($sql_auth) )
{
	message_die(GENERAL_ERROR, 'could not query forums information.', '', __LINE__, __FILE__, $sql_auth);
}
$forums = array();
while( $row_auth = $db->sql_fetchrow($result_auth) )
{
	$forums[] = $row_auth;
}
$db->sql_freeresult($result_auth);

$is_auth_ary = array();
$is_auth_ary = auth(AUTH_ALL, AUTH_LIST_ALL, $userdata);

$except_forums = '\'start\'';
for( $f = 0; $f < count($forums); $f++ )
{
	if( (!$is_auth_ary[$forums[$f]['forum_id']]['auth_read']) || (!$is_auth_ary[$forums[$f]['forum_id']]['auth_view']) )
	{
		if( $except_forums == '\'start\'' )
		{
			$except_forums = $forums[$f]['forum_id'];
		}
		else
		{
			$except_forums .= ','. $forums[$f]['forum_id'];
		}
	}
}

$where_forums = ( $special_forums == '0' ) ? 't.forum_id NOT IN ('. $except_forums .')' : 't.forum_id NOT IN ('. $except_forums .') AND t.forum_id IN ('. $forum_ids .')';
$sql = "SELECT t.*, f.forum_id, f.forum_name, u.username AS first_poster, u.user_id AS first_poster_id, u2.username AS last_poster, u2.user_id AS last_poster_id, p.post_username AS first_poster_name, p2.post_username AS last_poster_name, p2.post_time, pt.*
	FROM ". TOPICS_TABLE ." t, ". FORUMS_TABLE ." f, ". USERS_TABLE ." u, ". POSTS_TABLE ." p, ". POSTS_TABLE ." p2, ". USERS_TABLE ." u2, ". POSTS_TEXT_TABLE ." pt
	WHERE $where_forums AND t.topic_poster = u.user_id AND f.forum_id = t.forum_id AND p.post_id = t.topic_first_post_id AND p2.post_id = t.topic_last_post_id AND u2.user_id = p2.poster_id AND t.topic_last_post_id = pt.post_id
	ORDER BY t.topic_last_post_id DESC LIMIT $topic_limit";
if( !$result = $db->sql_query($sql) )
{
	message_die(GENERAL_ERROR, 'could not obtain main information.', '', __LINE__, __FILE__, $sql);
}
$line = array();
while( $row = $db->sql_fetchrow($result) )
{
	$line[] = $row;
}
$db->sql_freeresult($result);
		
$orig_word = array();
$replacement_word = array();
obtain_word_list($orig_word, $replacement_word);

$tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] .'_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] .'_t']) : array();
$tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] .'_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] .'_f']) : array();
for( $i = 0; $i < count($line); $i++ )
{
	$forum_id = $line[$i]['forum_id'];
	$forum_url = append_sid("viewforum.$phpEx?". POST_FORUM_URL ."=$forum_id");
	$topic_id = $line[$i]['topic_id'];
	$topic_url = append_sid("viewtopic.$phpEx?". POST_TOPIC_URL ."=$topic_id");

	$word_censor = ( count($orig_word) ) ? preg_replace($orig_word, $replacement_word, $line[$i]['topic_title']) : $line[$i]['topic_title'];
	$topic_title = ( strlen($line[$i]['topic_title']) < $topic_length ) ? $word_censor : substr(stripslashes($word_censor), 0, $topic_length) .'...';

	$topic_type =  ( $line[$i]['topic_type'] == POST_ANNOUNCE ) ? $lang['Topic_Announcement'] .' ': '';
	$topic_type .= ( $line[$i]['topic_type'] == POST_GLOBAL_ANNOUNCE ) ? $lang['Topic_global_announcement'] .' ': '';
	$topic_type .= ( $line[$i]['topic_type'] == POST_STICKY ) ? $lang['Topic_Sticky'] .' ': '';
	$topic_type .= ( $line[$i]['topic_vote'] ) ? $lang['Topic_Poll'] .' ': '';

	$goto_page = '';

	if( $userdata['session_logged_in'] )
	{
		if( $line[$i]['post_time'] > $userdata['user_lastvisit'] ) 
		{
			if( !empty($tracking_topics) || !empty($tracking_forums) || isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] .'_f_all']) )
			{
				$unread_topics = true;
				if( !empty($tracking_topics[$topic_id]) )
				{
					if( $tracking_topics[$topic_id] >= $line[$i]['post_time'] )
					{
						$unread_topics = false;
					}
				}
				if( !empty($tracking_forums[$forum_id]) )
				{
					if( $tracking_forums[$forum_id] >= $line[$i]['post_time'] )
					{
						$unread_topics = false;
					}
				}
				if( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] .'_f_all']) )
				{
					if( $HTTP_COOKIE_VARS[$board_config['cookie_name'] .'_f_all'] >= $line[$i]['post_time'] )
					{
						$unread_topics = false;
					}
				}

				if( $unread_topics )
				{
					$folder_image = $folder_new;
					$folder_alt = $lang['New_posts'];
					$newest_img = '<a href="'. append_sid("viewtopic.$phpEx?". POST_TOPIC_URL ."=$topic_id&view=newest") .'"><img src="'. $images['icon_newest_reply'] .'" alt="'. $lang['View_newest_post'] .'" title="'. $lang['View_newest_post'] .'" border="0" /></a> ';
				}
				else
				{
					$folder_image = $folder;
					$folder_alt = ( $line[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
					$newest_img = '<a href="'. append_sid("viewtopic.$phpEx?". POST_TOPIC_URL ."=$topic_id&view=newest") .'"><img src="'. $images['icon_latest_reply'] .'" alt="'. $lang['View_latest_post'] .'" title="'. $lang['View_latest_post'] .'" border="0" /></a> ';
				}
			}
			else
			{
				$folder_image = $folder_new;
				$folder_alt = ( $line[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['New_posts'];
				$newest_img = '<a href="'. append_sid("viewtopic.$phpEx?". POST_TOPIC_URL ."=$topic_id&view=newest") .'"><img src="'. $images['icon_newest_reply'] .'" alt="'. $lang['View_newest_post'] .'" title="'. $lang['View_newest_post'] .'" border="0" /></a> ';
			}
		}
		else 
		{
			$folder_image = $folder;
			$folder_alt = ( $line[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
			$newest_img = '<a href="'. append_sid("viewtopic.$phpEx?". POST_TOPIC_URL ."=$topic_id&view=newest") .'"><img src="'. $images['icon_latest_reply'] .'" alt="'. $lang['View_latest_post'] .'" title="'. $lang['View_latest_post'] .'" border="0" /></a> ';
		}
	}
	else
	{
		$folder_image = $folder;
		$folder_alt = ( $line[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
		$newest_img = '<a href="'. append_sid("viewtopic.$phpEx?". POST_TOPIC_URL ."=$topic_id&view=newest") .'"><img src="'. $images['icon_latest_reply'] .'" alt="'. $lang['View_latest_post'] .'" title="'. $lang['View_latest_post'] .'" border="0" /></a> ';
	}

	
	$last_time = create_date($board_config['default_dateformat'], $line[$i]['post_time'], $board_config['board_timezone']);
	$last_author = ( $line[$i]['last_poster_id'] != ANONYMOUS ) ? '<a href="'. append_sid("profile.$phpEx?mode=viewprofile&". POST_USERS_URL .'='. $line[$i]['last_poster_id']) .'">'. $line[$i]['last_poster'] .'</a>' : ( ($line[$i]['last_poster_name'] != '' ) ? $line[$i]['last_poster_name'] : $lang['Guest'] );
	$last_url = '<a href="'. append_sid("viewtopic.$phpEx?". POST_POST_URL .'='. $line[$i]['topic_last_post_id']) .'#'. $line[$i]['topic_last_post_id'] .'"><img src="'. $images['icon_latest_reply'] .'" alt="'. $lang['View_latest_post'] .'" title="'. $lang['View_latest_post'] .'" border="0" /></a>';


	$template->assign_block_vars('recent', array(
		'TOPIC_TITLE' => $topic_title,
		'LAST_TIME' => $last_time,
		'LAST_AUTHOR' => $last_author,
		'NEWEST_IMG' => $newest_img,
		'LAST_URL' => $last_url,
		'FORUM_NAME' => $line[$i]['forum_name'],
		'U_VIEW_FORUM' => $forum_url,
		'U_VIEW_TOPIC' => $topic_url,
	));
}
// die letzten Themen ENDE
Garfield312
Mitglied
Beiträge: 528
Registriert: 03.09.2004 15:54

Beitrag von Garfield312 »

Danke für die Antwort.

Hm, das dauert mit deinem Codeblock noch länger als mit meinem...

Deiner: 17,03 s

Meiner: 9,31 s

Sehr komisch 8)
Viele Grüße, Garfield.
Benutzeravatar
Gumfuzi
Ehemaliges Teammitglied
Beiträge: 2454
Registriert: 26.03.2004 22:25
Wohnort: Linz, AT
Kontaktdaten:

Beitrag von Gumfuzi »

komisch, bei mir lief der ca. 10x schneller als der original - aber ev. gibt es ja einen offizielle Fix dafür bei AWSW...
Garfield312
Mitglied
Beiträge: 528
Registriert: 03.09.2004 15:54

Beitrag von Garfield312 »

AWSW ist doch dauerhaft down ?
Viele Grüße, Garfield.
Benutzeravatar
Gumfuzi
Ehemaliges Teammitglied
Beiträge: 2454
Registriert: 26.03.2004 22:25
Wohnort: Linz, AT
Kontaktdaten:

Beitrag von Gumfuzi »

mmmh, ja, das ist echt blöd... :(
Elektron
Mitglied
Beiträge: 128
Registriert: 10.01.2005 21:42

Beitrag von Elektron »

Hallo,
gibt es eine Möglichkeit diese sql-Abfrage in einer Log-Datei zu speichern um dies dem Provider als Beweis vorzulegen?

Habe derzeit so ein Problem und würde gerne über eine bestimmt Zeitraum mitloggen und dies dann dem Provider vorlegen incl. einem Zeitstempel vorlegen.

Gruß Elektron
Benutzeravatar
Gumfuzi
Ehemaliges Teammitglied
Beiträge: 2454
Registriert: 26.03.2004 22:25
Wohnort: Linz, AT
Kontaktdaten:

Beitrag von Gumfuzi »

Elektron
Mitglied
Beiträge: 128
Registriert: 10.01.2005 21:42

Beitrag von Elektron »

super! Danke genau das was ich gesucht habe :grin: ... doch leider nicht selbst gefunden :(

Gruß Elektron
Benutzeravatar
bgx
Mitglied
Beiträge: 228
Registriert: 30.11.2005 22:32
Kontaktdaten:

Beitrag von bgx »

Schade, ich bekomme auch nichts angezeigt, dabei hab ich genau nach soetwas gesucht. :roll:

EDIT: Jetzt geht er! nicht in der mysql.php sondern in der mysql4.php dann klappt es. :wink:
Benutzeravatar
Gumfuzi
Ehemaliges Teammitglied
Beiträge: 2454
Registriert: 26.03.2004 22:25
Wohnort: Linz, AT
Kontaktdaten:

Beitrag von Gumfuzi »

bgx hat geschrieben:Schade, ich bekomme auch nichts angezeigt, dabei hab ich genau nach soetwas gesucht. :roll:

EDIT: Jetzt geht er! nicht in der mysql.php sondern in der mysql4.php dann klappt es. :wink:
naja, je nachdem, welches DB-System Du verwendest, habe es nicht auf allen testen können...
Antworten

Zurück zu „Coding & Technik“