From a5623a203974032bcadbb2d73dd9492fd5e0f8d5 Mon Sep 17 00:00:00 2001 From: Selt <83926739+seltonmt012@users.noreply.github.com> Date: Sat, 8 Aug 2026 16:50:53 +0200 Subject: [PATCH] fix(es_extended/server/modules/createJob): cache only the grades that were inserted A grade that already exists in the database is skipped for the insert, but it was still written to ESX.Jobs. A second CreateJob call therefore replaced the stored name, label and salary in memory while the row itself kept the old values, and the two only agreed again after a restart. CreateJob now caches just the grades it inserted. Label and type of an existing job come from the database for the same reason. The grade lookup compares strings, so passing grade "1" for an existing grade 1 no longer inserts a second row. --- [core]/es_extended/server/modules/createJob.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/[core]/es_extended/server/modules/createJob.lua b/[core]/es_extended/server/modules/createJob.lua index 48f55540..f27172e5 100644 --- a/[core]/es_extended/server/modules/createJob.lua +++ b/[core]/es_extended/server/modules/createJob.lua @@ -52,14 +52,17 @@ function ESX.CreateJob(name, label, grades, jobType) jobType = "civ" end - local jobExists = MySQL.scalar.await('SELECT 1 FROM `jobs` WHERE `name` = ?', { name }) ~= nil + local existingJob = MySQL.single.await('SELECT `label`, `type` FROM `jobs` WHERE `name` = ?', { name }) + local jobExists = existingJob ~= nil local existingGrades = {} if jobExists then + label, jobType = existingJob.label, existingJob.type + local rows = MySQL.query.await('SELECT `grade` FROM `job_grades` WHERE `job_name` = ?', { name }) for i = 1, #(rows or {}) do - existingGrades[rows[i].grade] = true + existingGrades[tostring(rows[i].grade)] = true end end @@ -72,8 +75,11 @@ function ESX.CreateJob(name, label, grades, jobType) } end + local newGrades = {} + for _, grade in pairs(grades) do - if not existingGrades[grade.grade] then + if not existingGrades[tostring(grade.grade)] then + newGrades[#newGrades + 1] = grade queries[#queries + 1] = { query = 'INSERT INTO job_grades (job_name, grade, name, label, salary, skin_male, skin_female) VALUES (?, ?, ?, ?, ?, ?, ?)', values = { name, grade.grade, grade.name, grade.label, grade.salary, grade.skin_male and json.encode(grade.skin_male) or '{}', grade.skin_female and json.encode(grade.skin_female) or '{}' } @@ -93,7 +99,7 @@ function ESX.CreateJob(name, label, grades, jobType) return success end - ESX.Jobs[name] = generateNewJobTable(name, label, grades, jobType) + ESX.Jobs[name] = generateNewJobTable(name, label, newGrades, jobType) notify("SUCCESS", currentResourceName, 'Job created successfully: `%s`', name)