where("title", $key)->orderBy("id", "DESC")->first(); if ($setting) { if ($strip_tags) { $setting->html = strip_tags($setting->html); } return $setting->html; } else { // Eğer ayar yoksa, default ile oluştur ekle2([ 'title' => $key, 'html' => $default ], "settings"); return $default; } } function setting_put($key, $data) { // Use transaction with retry logic to prevent deadlocks $maxRetries = 3; $attempt = 0; while ($attempt < $maxRetries) { try { DB::transaction(function() use ($key, $data) { db("settings")->updateOrInsert([ 'title' => $key ], [ 'title' => $key, 'html' => $data ]); }); // Cache the value for faster reads Cache::put("setting_{$key}", $data, 3600); // 1 hour cache return true; } catch (\Illuminate\Database\QueryException $e) { // If deadlock detected, retry if ($e->getCode() == '40001' || strpos($e->getMessage(), 'Deadlock') !== false || strpos($e->getMessage(), 'Lock wait timeout') !== false) { $attempt++; if ($attempt >= $maxRetries) { throw $e; // Rethrow if max retries reached } usleep(100000 * $attempt); // Wait 100ms * attempt number before retry } else { throw $e; // Rethrow other exceptions immediately } } } } ?>