SetPData and or GetPData freezes the game for a split second. Is there a solution?

Why does this happen? I’m only storing and loading a number.

I thought SQL was supposed to be fast and all. Maybe it’s because it isn’t threaded or something. (I don’t know anything about SQL)

[lua]
function fishingmod.GainEXP(ply, amount)
ply:SetPData(“fishingmod exp”, ply:GetPData(“fishingmod exp”, 0) + amount)
ply:SetPData(“fishingmod catch”, ply:GetPData(“fishingmod catch”, 0) + 1)
fishingmod.UpdatePlayerInfo(ply)
end
[/lua]

Because you’re doing 4 SQL queries when all you need is one.
[lua]
local Queries = {
Update = “UPDATE Fishingmod SET Catches = %d, Exp = %d WHERE UniqueID = %d”,
Get = “SELECT * FROM Fishingmod WHERE UniqueID = %d”,
Create = “INSERT INTO Fishingmod( UniqueID, Exp, Catches ) VALUES( %d, 0, 0 )”,
Table = “CREATE TABLE Fishingmod ( UniqueID int, Catches int, Exp int )”
}

function fishingmod.GainEXP(ply, Amount )
ply.Exp = ply.Exp + Amount
ply.Catches = ply.Catches + 1
sql.Query( Queries.Update:format( ply.Catches, ply.Exp, ply:UniqueID() ) )
end

hook.Add( “PlayerInitialSpawn”, “Fishingmod.PlayerJoined”, function( ply )
local Query = sql.Query( Queries.Get:format( ply:UniqueID() ) )
if( !Query ) then
sql.Query( Queries.Create:format( ply:UniqueID() ) )
ply.Catches = 0
ply.Exp = 0
return
end
ply.Catches = Query.Catches
ply.Exp = Query.Exp
end )

hook.Add( “InitPostEntity”, “Fishingmod.Initialize”, function()
if( !sql.TableExists( “Fishingmod” ) ) then
sql.Query( Queries.Table )
end
end )[/lua]