• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Optimizing Looping All Streamer Objects
#1
Hi!?

It's my first time posting here but I would like to know is there any possibilities that I can optimize this code? It causes a huge lag spike in the server when used in a live server. It occurs when this loop is called when removing a furniture/land object or removing the entire furniture/land object.?(This also happens when the script has to reload the furniture/land object)

The lag can also be noticed?when deleting a house (which removes all the furniture in the process)

Things to know; My server has 16,000 objects so it is no surprise that the loop will check each single objects in the server.

I will be showing the functions (codes) that calls the loop:

PHP Code:
RemoveFurniture(objectid)
{
? ? if(
IsValidDynamicObject(objectid) && Streamer_GetExtraInt(objectidE_OBJECT_TYPE) == E_OBJECT_FURNITURE)
{
new
? ? ? ? 
id Streamer_GetExtraInt(objectidE_OBJECT_INDEX_ID);

? ? 
DeleteFurnitureObject(objectid);

? ? 
mysql_format(mysql_connectionqueryBuffersizeof(queryBuffer), "DELETE FROM furniture WHERE id = %i"id);
? ? 
mysql_tquery(mysql_connectionqueryBuffer);
}
}

DeleteFurnitureObject(objectid)
{
if(
IsValidDynamicObject(objectid) && Streamer_GetExtraInt(objectidE_OBJECT_TYPE) == E_OBJECT_FURNITURE)
{
? ? new 
Text3D:textid Text3D:Streamer_GetExtraInt(objectidE_OBJECT_3DTEXT_ID);

? ? ? ? if(
IsValidDynamic3DTextLabel(textid))
? ? ? ? {
? ? ? ? ? ? 
DestroyDynamic3DTextLabel(textid);
? ? ? ? }

? ? ? ? 
DestroyDynamicObject(objectid);
}
}

RemoveAllFurniture(houseid)
{
? ? if(
HouseInfo[houseid][hID] > 0)
{
? ? for(new 
0<= Streamer_GetUpperBound(STREAMER_TYPE_OBJECT); )
? ? {
? ? ? ? if(
IsValidDynamicObject(i) && Streamer_GetExtraInt(iE_OBJECT_TYPE) == E_OBJECT_FURNITURE && Streamer_GetExtraInt(iE_OBJECT_EXTRA_ID) == HouseInfo[houseid][hID])
? ? ? ? {
? ? ? ? ? ? 
DeleteFurnitureObject(i);
}
}

mysql_format(mysql_connectionqueryBuffersizeof(queryBuffer), "DELETE FROM furniture WHERE houseid = %i"HouseInfo[houseid][hID]);
mysql_tquery(mysql_connectionqueryBuffer);
}
}

ReloadFurniture(objectidlabels)
{
if(
IsValidDynamicObject(objectid) && Streamer_GetExtraInt(objectidE_OBJECT_TYPE) == E_OBJECT_FURNITURE)
{
? ? new
? ? ? ? 
id Streamer_GetExtraInt(objectidE_OBJECT_INDEX_ID);

? ? 
DeleteFurnitureObject(objectid);

? ? 
mysql_format(mysql_connectionqueryBuffersizeof(queryBuffer), "SELECT * FROM furniture WHERE id = %i"id);
? ? 
mysql_tquery(mysql_connectionqueryBuffer"SQL_LoadFurnitures""i"labels);
}
}

ReloadAllFurniture(houseid)
{
? ? if(
HouseInfo[houseid][hID] > 0)
{
? ? for(new 
0<= Streamer_GetUpperBound(STREAMER_TYPE_OBJECT); )
? ? {
? ? ? ? if(
IsValidDynamicObject(i) && Streamer_GetExtraInt(iE_OBJECT_TYPE) == E_OBJECT_FURNITURE && Streamer_GetExtraInt(iE_OBJECT_EXTRA_ID) == HouseInfo[houseid][hID])
? ? ? ? {
? ? ? ? ? ? 
DeleteFurnitureObject(i);
}
}

mysql_format(mysql_connectionqueryBuffersizeof(queryBuffer), "SELECT * FROM furniture WHERE houseid = %i"HouseInfo[houseid][hID]);
mysql_tquery(mysql_connectionqueryBuffer"SQL_LoadFurnitures""i"HouseInfo[houseid][hLabels]);
}


I will be editing this thread if more codes are needed.
  Reply


Messages In This Thread
Optimizing Looping All Streamer Objects - by JaKe Elite - 2020-09-30, 10:12 PM

Forum Jump: