Raised This Month: $32 Target: $400
 8% 

SQL query is freezing players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jackie12
Junior Member
Join Date: Oct 2009
Old 05-21-2017 , 16:00   SQL query is freezing players
Reply With Quote #1

Hello guys,

I've got little problem. On every round end I am updating in my database players stats (kills,assists,deaths,mvp). While script to update is running, it is freezing for 0.5 sec every player. How can I solve it? Thank you ... here is code

Code:
RoundsWon_T = CS_GetTeamScore(CS_TEAM_T);
	RoundsWon_CT = CS_GetTeamScore(CS_TEAM_CT);
	for (int i = 1; i <= MaxClients; i++)
	{
		if (IsClientValid(i)) {
			new String:query[255];
			new String:auth[32];
			new String:part[25];
				
			GetClientAuthId(i, AuthId_Steam2, auth, sizeof(auth), false);
			new index = StrContains( auth, ":" );
			index += strlen( ":" );
			strcopy( part, sizeof(part), auth[ index ] );
				
			Format(query, 255, "UPDATE allowed_players SET frags='%i', assists='%i', deaths='%i', mvp='%i', win_rounds='%i' WHERE match_id='%i' AND steamid='%s' LIMIT 1", GetClientFrags(i), CS_GetClientAssists(i), GetClientDeaths(i), CS_GetMVPCount(i), GetClientTeam(i) == CS_TEAM_CT ? RoundsWon_CT : RoundsWon_T, matchId, part);
			SQL_Query(db, query);
		}
	}
jackie12 is offline
africanspacejesus
Senior Member
Join Date: Nov 2016
Location: Bay Area, CA
Old 05-21-2017 , 16:29   Re: SQL query is freezing players
Reply With Quote #2

Use a threaded query instead, this allows the queries to run on a different core and not effect the gameserver in the case that the query isn't instant

https://sm.alliedmods.net/new-api/dbi/SQL_TQuery
__________________
Taking paid plugin requests
africanspacejesus is offline
jackie12
Junior Member
Join Date: Oct 2009
Old 05-23-2017 , 04:08   Re: SQL query is freezing players
Reply With Quote #3

Thank you so much. It seems that it is working
jackie12 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:37.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode