diff --git a/admin/src/views/tag/form.vue b/admin/src/views/tag/form.vue index 91001a99..db984ca0 100644 --- a/admin/src/views/tag/form.vue +++ b/admin/src/views/tag/form.vue @@ -7,10 +7,30 @@ - + + + + + + + + + + + + + + + + + + + + + @@ -47,7 +67,12 @@ export default { formData: { color: '', name: '', - priority: '' + priority: '', + font_color: '#ffffff', + font_size: '12px', + margin: 0, + padding: 0, + border_radius: 0, }, rules: { color: [ @@ -64,6 +89,11 @@ export default { state.formData.name = res.data.name state.formData.color = res.data.color state.formData.priority = res.data.priority + state.formData.font_color = res.data.font_color + state.formData.font_size = res.data.font_size + state.formData.margin = res.data.margin + state.formData.padding = res.data.padding + state.formData.border_radius = res.data.border_radius }) } diff --git a/admin/src/views/tag/index.vue b/admin/src/views/tag/index.vue index 9a5c894d..5570ce45 100644 --- a/admin/src/views/tag/index.vue +++ b/admin/src/views/tag/index.vue @@ -33,7 +33,37 @@ + + + + + + + + + + + + + + + @@ -48,12 +78,6 @@ label="Updated at" > - - - validate($this->getRules()); - $data = $request->all(); - if (isset($data['priority'])) { - $data['priority'] = intval($data['priority']); - } + $data = array_filter($request->all()); $result = $this->repository->store($data); $resource = new TagResource($result); return $this->success($resource); diff --git a/app/Http/Resources/TagResource.php b/app/Http/Resources/TagResource.php index 7a7b1bc2..c2a646e4 100644 --- a/app/Http/Resources/TagResource.php +++ b/app/Http/Resources/TagResource.php @@ -18,6 +18,11 @@ class TagResource extends JsonResource 'id' => $this->id, 'name' => $this->name, 'color' => $this->color, + 'font_color' => $this->font_color, + 'font_size' => $this->font_size, + 'padding' => $this->padding, + 'margin' => $this->margin, + 'border_radius' => $this->border_radius, 'priority' => $this->priority, 'created_at' => format_datetime($this->created_at), 'updated_at' => format_datetime($this->updated_at), diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 7230f10e..d53fa73e 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -3,6 +3,8 @@ namespace App\Models; use Illuminate\Support\Arr; +use Illuminate\Support\Facades\Cache; +use Nexus\Database\NexusDB; class Setting extends NexusModel { @@ -10,9 +12,9 @@ class Setting extends NexusModel public static function get($name = null) { - static $settings; - if (is_null($settings)) { + $settings = NexusDB::remember("nexus_settings_in_laravel", 10, function () { $rows = self::query()->get(['name', 'value']); + $result = []; foreach ($rows as $row) { $value = $row->value; if (!is_null($value)) { @@ -21,9 +23,10 @@ class Setting extends NexusModel $value = $arr; } } - Arr::set($settings, $row->name, $value); + Arr::set($result, $row->name, $value); } - } + return $result; + }); if (is_null($name)) { return $settings; } diff --git a/app/Models/Tag.php b/app/Models/Tag.php index 76f1ecc8..51ea03c6 100644 --- a/app/Models/Tag.php +++ b/app/Models/Tag.php @@ -7,7 +7,7 @@ class Tag extends NexusModel public $timestamps = true; protected $fillable = [ - 'id', 'name', 'color', 'priority', 'created_at', 'updated_at' + 'id', 'name', 'color', 'priority', 'created_at', 'updated_at', 'font_size', 'font_color', 'padding', 'margin', 'border_radius' ]; const DEFAULTS = [ diff --git a/app/Repositories/TagRepository.php b/app/Repositories/TagRepository.php index 2109bc74..01667dcf 100644 --- a/app/Repositories/TagRepository.php +++ b/app/Repositories/TagRepository.php @@ -67,7 +67,10 @@ class TagRepository extends BaseRepository foreach ($renderIdArr as $tagId) { $value = $tagKeyById->get($tagId); if ($value) { - $item = "color};color:white;border-radius:15%\">{$value->name} "; + $item = sprintf( + "%s", + $value->color, $value->font_color, $value->border_radius, $value->font_size, $value->margin, $value->padding, $value->name + ); if ($withFilterLink) { $html .= sprintf('%s', $tagId, $item); } else { diff --git a/app/Repositories/TrackerRepository.php b/app/Repositories/TrackerRepository.php index 3a4ad288..aea868f1 100644 --- a/app/Repositories/TrackerRepository.php +++ b/app/Repositories/TrackerRepository.php @@ -661,8 +661,17 @@ class TrackerRepository extends BaseRepository } + /** + * + * @param Torrent $torrent + * @param $queries + */ private function updateTorrent(Torrent $torrent, $queries) { + if (empty($queries['event'])) { + do_log("no event, return", 'debug'); + return; + } $torrent->seeders = Peer::query() ->where('torrent', $torrent->id) ->where('to_go', '=',0) diff --git a/database/migrations/2022_03_26_162038_add_margin_padding_to_tags_table.php b/database/migrations/2022_03_26_162038_add_margin_padding_to_tags_table.php new file mode 100644 index 00000000..adbe7320 --- /dev/null +++ b/database/migrations/2022_03_26_162038_add_margin_padding_to_tags_table.php @@ -0,0 +1,36 @@ +string('padding')->default(0); + $table->string('margin')->default('0 4px 0 0'); + $table->string('border_radius')->default(0); + $table->string('font_size')->default('12px'); + $table->string('font_color')->default('#ffffff'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('tags', function (Blueprint $table) { + $table->dropColumn(['padding', 'margin', 'font_size', 'font_color', 'border_radius']); + }); + } +} diff --git a/include/core.php b/include/core.php index 7ffa5f70..b97a428c 100644 --- a/include/core.php +++ b/include/core.php @@ -12,7 +12,6 @@ if (!file_exists($rootpath . '.env')) { require $rootpath . 'nexus/Database/helpers.php'; require $rootpath . 'classes/class_cache_redis.php'; require $rootpath . 'include/eloquent.php'; -require $rootpath . 'include/config.php'; ini_set('date.timezone', nexus_config('nexus.timezone')); ini_set('error_reporting', E_ALL); @@ -24,6 +23,8 @@ if (!in_array(nexus()->getScript(), ['announce', 'scrape'])) { } $Cache = new class_cache_redis(); //Load the caching class $Cache->setLanguageFolderArray(get_langfolder_list()); +require $rootpath . 'include/config.php'; + define('TIMENOW', time()); $USERUPDATESET = array(); $query_name=array(); diff --git a/include/globalfunctions.php b/include/globalfunctions.php index 49ab617f..26782ae0 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -282,19 +282,23 @@ function get_setting($name = null) { static $settings; if (is_null($settings)) { - //get all settings from database - $sql = "select name, value from settings"; - $result = sql_query($sql); - while ($row = mysql_fetch_assoc($result)) { - $value = $row['value']; - if (!is_null($value)) { - $arr = json_decode($value, true); - if (is_array($arr)) { - $value = $arr; + $settings = \Nexus\Database\NexusDB::remember("nexus_settings_in_nexus" . __METHOD__, 10, function () { + //get all settings from database + $sql = "select name, value from settings"; + $result = sql_query($sql); + $final = []; + while ($row = mysql_fetch_assoc($result)) { + $value = $row['value']; + if (!is_null($value)) { + $arr = json_decode($value, true); + if (is_array($arr)) { + $value = $arr; + } } + arr_set($final, $row['name'], $value); } - arr_set($settings, $row['name'], $value); - } + return $final; + }); } if (is_null($name)) { return $settings; diff --git a/nexus/Database/NexusDB.php b/nexus/Database/NexusDB.php index 5b938750..e04521f2 100644 --- a/nexus/Database/NexusDB.php +++ b/nexus/Database/NexusDB.php @@ -4,6 +4,7 @@ namespace Nexus\Database; use Illuminate\Database\Capsule\Manager as Capsule; use Illuminate\Database\Query\Expression; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; class NexusDB @@ -267,6 +268,24 @@ class NexusDB return DB::transaction($callback, $attempts); } + public static function remember($key, $ttl, \Closure $callback) + { + if (IN_NEXUS) { + global $Cache; + $result = $Cache->get_value($key); + if ($result === false) { + do_log("cache miss, get from database."); + $result = $callback(); + $Cache->cache_value($key, $result, $ttl); + } else { + do_log("cache hit."); + } + return $result; + } else { + return Cache::remember($key, $ttl, $callback); + } + } + public static function getMysqlColumnInfo($table, $column) { static $driver; diff --git a/public/announce.php b/public/announce.php index 6785af6c..dab58034 100644 --- a/public/announce.php +++ b/public/announce.php @@ -164,7 +164,7 @@ else{ if ($newnumpeers > $rsize) $limit = " ORDER BY RAND() LIMIT $rsize"; else $limit = ""; -$announce_wait = 30; +$announce_wait = \App\Repositories\TrackerRepository::MIN_ANNOUNCE_WAIT_SECOND; $fields = "seeder, peer_id, ip, port, uploaded, downloaded, (".TIMENOW." - UNIX_TIMESTAMP(last_action)) AS announcetime, UNIX_TIMESTAMP(prev_action) AS prevts"; //$peerlistsql = "SELECT ".$fields." FROM peers WHERE torrent = ".$torrentid." AND connectable = 'yes' ".$only_leech_query.$limit; @@ -199,7 +199,7 @@ $params = $_GET; unset($params['key']); $lockKey = md5(http_build_query($params)); $redis = $Cache->getRedis(); -if (!$redis->set($lockKey, TIMENOW, ['nx', 'ex' => $announce_wait])) { +if (!$redis->set($lockKey, TIMENOW, ['nx', 'ex' => 5])) { do_log('ReAnnounce'); benc_resp($rep_dict); exit();