mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-28 06:57:22 +08:00
move cleanup: seed bonus and seeding leeching time to job
This commit is contained in:
@@ -80,3 +80,5 @@ SFTP_PORT=
|
|||||||
SFTP_ROOT=/tmp
|
SFTP_ROOT=/tmp
|
||||||
|
|
||||||
UID_STARTS=10001
|
UID_STARTS=10001
|
||||||
|
|
||||||
|
PHP_PATH=
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Jobs\CalculateSeedBonus;
|
||||||
|
use App\Jobs\UpdateSeedingLeechingTime;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class Cleanup extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'cleanup {--action=} {--begin_uid=} {--end_uid=}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Cleanup async job trigger, options: --begin_uid, --end_uid, --action (seed_bonus, seeding_leeching_time)';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$action = $this->option('action');
|
||||||
|
$beginUid = $this->option('begin_uid');
|
||||||
|
$endUid = $this->option('end_uid');
|
||||||
|
$this->info("beginUid: $beginUid, endUid: $endUid, action: $action");
|
||||||
|
if ($action == 'seed_bonus') {
|
||||||
|
CalculateSeedBonus::dispatch($beginUid, $endUid);
|
||||||
|
} elseif ($action == 'seeding_leeching_time') {
|
||||||
|
UpdateSeedingLeechingTime::dispatch($beginUid, $endUid);
|
||||||
|
} else {
|
||||||
|
$msg = "Invalid action: $action";
|
||||||
|
do_log($msg, 'error');
|
||||||
|
$this->error($msg);
|
||||||
|
}
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Filament;
|
namespace App\Filament;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
use Filament\Resources\Pages\ManageRecords;
|
use Filament\Resources\Pages\ManageRecords;
|
||||||
use Filament\Tables\Filters\Layout;
|
use Filament\Tables\Filters\Layout;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class PageListSingle extends ManageRecords
|
class PageListSingle extends ManageRecords
|
||||||
{
|
{
|
||||||
@@ -13,4 +15,11 @@ class PageListSingle extends ManageRecords
|
|||||||
{
|
{
|
||||||
return Layout::AboveContent;
|
return Layout::AboveContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getTableRecordUrlUsing(): ?Closure
|
||||||
|
{
|
||||||
|
return function (Model $record): ?string {
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Filament\Resources\System;
|
|||||||
|
|
||||||
use App\Filament\Resources\System\PluginResource\Pages;
|
use App\Filament\Resources\System\PluginResource\Pages;
|
||||||
use App\Filament\Resources\System\PluginResource\RelationManagers;
|
use App\Filament\Resources\System\PluginResource\RelationManagers;
|
||||||
|
use App\Jobs\ManagePlugin;
|
||||||
use App\Models\Plugin;
|
use App\Models\Plugin;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
use Filament\Resources\Form;
|
use Filament\Resources\Form;
|
||||||
@@ -52,6 +53,7 @@ class PluginResource extends Resource
|
|||||||
Tables\Columns\TextColumn::make('remote_url')->label(__('plugin.labels.remote_url')),
|
Tables\Columns\TextColumn::make('remote_url')->label(__('plugin.labels.remote_url')),
|
||||||
Tables\Columns\TextColumn::make('installed_version')->label(__('plugin.labels.installed_version')),
|
Tables\Columns\TextColumn::make('installed_version')->label(__('plugin.labels.installed_version')),
|
||||||
Tables\Columns\TextColumn::make('statusText')->label(__('label.status')),
|
Tables\Columns\TextColumn::make('statusText')->label(__('label.status')),
|
||||||
|
Tables\Columns\TextColumn::make('updated_at')->label(__('plugin.labels.updated_at')),
|
||||||
])
|
])
|
||||||
->filters([
|
->filters([
|
||||||
//
|
//
|
||||||
@@ -76,10 +78,11 @@ class PluginResource extends Resource
|
|||||||
$actions[] = self::buildInstallAction();
|
$actions[] = self::buildInstallAction();
|
||||||
$actions[] = self::buildUpdateAction();
|
$actions[] = self::buildUpdateAction();
|
||||||
$actions[] = Tables\Actions\DeleteAction::make('delete')
|
$actions[] = Tables\Actions\DeleteAction::make('delete')
|
||||||
->hidden(fn ($record) => $record->status == Plugin::STATUS_NOT_INSTALLED)
|
->hidden(fn ($record) => !in_array($record->status, Plugin::$showDeleteBtnStatus))
|
||||||
->using(function ($record) {
|
->using(function ($record) {
|
||||||
$record->update(['status' => Plugin::STATUS_PRE_DELETE]);
|
$record->update(['status' => Plugin::STATUS_PRE_DELETE]);
|
||||||
});
|
ManagePlugin::dispatch($record, 'delete');
|
||||||
|
});
|
||||||
return $actions;
|
return $actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,9 +92,10 @@ class PluginResource extends Resource
|
|||||||
->label(__('plugin.actions.install'))
|
->label(__('plugin.actions.install'))
|
||||||
->icon('heroicon-o-arrow-down')
|
->icon('heroicon-o-arrow-down')
|
||||||
->requiresConfirmation()
|
->requiresConfirmation()
|
||||||
->hidden(fn ($record) => $record->status == Plugin::STATUS_NORMAL)
|
->hidden(fn ($record) => !in_array($record->status, Plugin::$showInstallBtnStatus))
|
||||||
->action(function ($record) {
|
->action(function ($record) {
|
||||||
$record->update(['status' => Plugin::STATUS_PRE_INSTALL]);
|
$record->update(['status' => Plugin::STATUS_PRE_INSTALL]);
|
||||||
|
ManagePlugin::dispatch($record, 'install');
|
||||||
})
|
})
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
@@ -102,9 +106,10 @@ class PluginResource extends Resource
|
|||||||
->label(__('plugin.actions.update'))
|
->label(__('plugin.actions.update'))
|
||||||
->icon('heroicon-o-arrow-up')
|
->icon('heroicon-o-arrow-up')
|
||||||
->requiresConfirmation()
|
->requiresConfirmation()
|
||||||
->hidden(fn ($record) => in_array($record->status, [Plugin::STATUS_NOT_INSTALLED, Plugin::STATUS_PRE_UPDATE]))
|
->hidden(fn ($record) => !in_array($record->status, Plugin::$showUpdateBtnStatus))
|
||||||
->action(function ($record) {
|
->action(function ($record) {
|
||||||
$record->update(['status' => Plugin::STATUS_PRE_UPDATE]);
|
$record->update(['status' => Plugin::STATUS_PRE_UPDATE]);
|
||||||
|
ManagePlugin::dispatch($record, 'update');
|
||||||
})
|
})
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,16 +2,15 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\System\PluginResource\Pages;
|
namespace App\Filament\Resources\System\PluginResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\PageListSingle;
|
||||||
use App\Filament\Resources\System\PluginResource;
|
use App\Filament\Resources\System\PluginResource;
|
||||||
use Filament\Pages\Actions;
|
use Filament\Pages\Actions;
|
||||||
use Filament\Resources\Pages\ManageRecords;
|
use Filament\Resources\Pages\ManageRecords;
|
||||||
|
|
||||||
class ManagePlugins extends ManageRecords
|
class ManagePlugins extends PageListSingle
|
||||||
{
|
{
|
||||||
protected static string $resource = PluginResource::class;
|
protected static string $resource = PluginResource::class;
|
||||||
|
|
||||||
protected ?string $maxContentWidth = 'full';
|
|
||||||
|
|
||||||
protected function getActions(): array
|
protected function getActions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Models\Setting;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Nexus\Database\NexusDB;
|
||||||
|
|
||||||
|
class CalculateSeedBonus implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
private int $beginUid;
|
||||||
|
|
||||||
|
private int $endUid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(int $beginUid, int $endUid)
|
||||||
|
{
|
||||||
|
$this->beginUid = $beginUid;
|
||||||
|
$this->endUid = $endUid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$beginTimestamp = time();
|
||||||
|
$logPrefix = sprintf("[CLEANUP_CLI_CALCULATE_SEED_BONUS], beginUid: %s, endUid: %s", $this->beginUid, $this->endUid);
|
||||||
|
$sql = sprintf("select userid from peers where userid > %s and userid <= %s and seeder = 'yes' group by userid", $this->beginUid, $this->endUid);
|
||||||
|
$results = NexusDB::select($sql);
|
||||||
|
$count = count($results);
|
||||||
|
do_log("$logPrefix, [GET_UID], sql: $sql, count: " . count($results));
|
||||||
|
if ($count == 0) {
|
||||||
|
do_log("$logPrefix, no user...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$haremAdditionFactor = Setting::get('bonus.harem_addition');
|
||||||
|
$officialAdditionFactor = Setting::get('bonus.official_addition');
|
||||||
|
$donortimes_bonus = Setting::get('bonus.donortimes');
|
||||||
|
$autoclean_interval_one = Setting::get('main.autoclean_interval_one');
|
||||||
|
$sql = sprintf("select %s from users where id in (%s)", implode(',', User::$commonFields), implode(',', array_column($results, 'userid')));
|
||||||
|
$results = NexusDB::select($sql);
|
||||||
|
do_log("$logPrefix, [GET_UID_REAL], count: " . count($results));
|
||||||
|
foreach ($results as $userInfo)
|
||||||
|
{
|
||||||
|
$uid = $userInfo['id'];
|
||||||
|
$isDonor = is_donor($userInfo);
|
||||||
|
$seedBonusResult = calculate_seed_bonus($uid);
|
||||||
|
$bonusLog = "[CLEANUP_CALCULATE_SEED_BONUS], user: $uid, seedBonusResult: " . nexus_json_encode($seedBonusResult);
|
||||||
|
$all_bonus = $seedBonusResult['seed_bonus'];
|
||||||
|
$bonusLog .= ", all_bonus: $all_bonus";
|
||||||
|
if ($isDonor) {
|
||||||
|
$all_bonus = $all_bonus * $donortimes_bonus;
|
||||||
|
$bonusLog .= ", isDonor, donortimes_bonus: $donortimes_bonus, all_bonus: $all_bonus";
|
||||||
|
}
|
||||||
|
if ($officialAdditionFactor > 0) {
|
||||||
|
$officialAddition = $seedBonusResult['official_bonus'] * $officialAdditionFactor;
|
||||||
|
$all_bonus += $officialAddition;
|
||||||
|
$bonusLog .= ", officialAdditionFactor: $officialAdditionFactor, official_bonus: {$seedBonusResult['official_bonus']}, officialAddition: $officialAddition, all_bonus: $all_bonus";
|
||||||
|
}
|
||||||
|
if ($haremAdditionFactor > 0) {
|
||||||
|
$haremBonus = calculate_harem_addition($uid);
|
||||||
|
$haremAddition = $haremBonus * $haremAdditionFactor;
|
||||||
|
$all_bonus += $haremAddition;
|
||||||
|
$bonusLog .= ", haremAdditionFactor: $haremAdditionFactor, haremBonus: $haremBonus, haremAddition: $haremAddition, all_bonus: $all_bonus";
|
||||||
|
}
|
||||||
|
$dividend = 3600 / $autoclean_interval_one;
|
||||||
|
$all_bonus = $all_bonus / $dividend;
|
||||||
|
$seed_points = $seedBonusResult['seed_points'] / $dividend;
|
||||||
|
$sql = "update users set seed_points = ifnull(seed_points, 0) + $seed_points, seedbonus = seedbonus + $all_bonus where id = $uid limit 1";
|
||||||
|
do_log("$bonusLog, query: $sql");
|
||||||
|
NexusDB::statement($sql);
|
||||||
|
}
|
||||||
|
$costTime = time() - $beginTimestamp;
|
||||||
|
do_log("$logPrefix, [DONE], cost time: $costTime seconds");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Models\Plugin;
|
||||||
|
use App\Repositories\PluginRepository;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class ManagePlugin implements ShouldQueue, ShouldBeUnique
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
private Plugin $plugin;
|
||||||
|
|
||||||
|
private string $action;
|
||||||
|
|
||||||
|
public int $uniqueFor = 600;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Plugin $plugin, string $action)
|
||||||
|
{
|
||||||
|
$this->plugin = $plugin;
|
||||||
|
$this->action = $action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function uniqueId()
|
||||||
|
{
|
||||||
|
return $this->plugin->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(PluginRepository $pluginRepository)
|
||||||
|
{
|
||||||
|
match ($this->action) {
|
||||||
|
'install' => $pluginRepository->doInstall($this->plugin),
|
||||||
|
'update' => $pluginRepository->doUpdate($this->plugin),
|
||||||
|
'delete' => $pluginRepository->doDelete($this->plugin),
|
||||||
|
default => throw new \InvalidArgumentException("Invalid action: " . $this->action)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Nexus\Database\NexusDB;
|
||||||
|
|
||||||
|
class UpdateSeedingLeechingTime implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
private int $beginUid;
|
||||||
|
|
||||||
|
private int $endUid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(int $beginUid, int $endUid)
|
||||||
|
{
|
||||||
|
$this->beginUid = $beginUid;
|
||||||
|
$this->endUid = $endUid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$beginTimestamp = time();
|
||||||
|
$logPrefix = sprintf("[CLEANUP_CLI_UPDATE_SEEDING_LEECHING_TIME], beginUid: %s, endUid: %s", $this->beginUid, $this->endUid);
|
||||||
|
$sql = sprintf("select id from users where id > %s and id <= %s and enabled = 'yes' and status = 'confirmed'", $this->beginUid, $this->endUid);
|
||||||
|
$results = NexusDB::select($sql);
|
||||||
|
do_log("$logPrefix, [GET_UID], sql: $sql, count: " . count($results));
|
||||||
|
foreach ($results as $arr) {
|
||||||
|
$uid = $arr['id'];
|
||||||
|
$sql = sprintf('select sum(seedtime) as st, sum(leechtime) as lt from snatched where userid = %s limit 1', $uid);
|
||||||
|
$row = NexusDB::select($sql);
|
||||||
|
if (is_numeric($row[0]['st'])) {
|
||||||
|
$sql = sprintf('update users set seedtime = %s, leechtime = %s where id = %s limit 1', $row[0]['st'], $row[0]['lt'], $uid);
|
||||||
|
NexusDB::statement($sql);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$costTime = time() - $beginTimestamp;
|
||||||
|
do_log("$logPrefix, [DONE], cost time: $costTime seconds");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,11 +3,14 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
class Plugin extends NexusModel
|
class Plugin extends NexusModel
|
||||||
{
|
{
|
||||||
protected $fillable = ['display_name', 'package_name', 'remote_url', 'installed_version', 'status', 'description', 'status_result'];
|
protected $fillable = ['display_name', 'package_name', 'remote_url', 'installed_version', 'status', 'description', 'status_result'];
|
||||||
|
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
const STATUS_NOT_INSTALLED = -1;
|
const STATUS_NOT_INSTALLED = -1;
|
||||||
const STATUS_NORMAL = 0;
|
const STATUS_NORMAL = 0;
|
||||||
|
|
||||||
@@ -23,6 +26,23 @@ class Plugin extends NexusModel
|
|||||||
const STATUS_DELETING = 102;
|
const STATUS_DELETING = 102;
|
||||||
const STATUS_DELETE_FAILED = 103;
|
const STATUS_DELETE_FAILED = 103;
|
||||||
|
|
||||||
|
public static array $showInstallBtnStatus = [
|
||||||
|
self::STATUS_NOT_INSTALLED,
|
||||||
|
self::STATUS_INSTALL_FAILED,
|
||||||
|
];
|
||||||
|
|
||||||
|
public static array $showUpdateBtnStatus = [
|
||||||
|
self::STATUS_NORMAL,
|
||||||
|
self::STATUS_UPDATE_FAILED,
|
||||||
|
self::STATUS_DELETE_FAILED,
|
||||||
|
];
|
||||||
|
|
||||||
|
public static array $showDeleteBtnStatus = [
|
||||||
|
self::STATUS_NORMAL,
|
||||||
|
self::STATUS_UPDATE_FAILED,
|
||||||
|
self::STATUS_DELETE_FAILED,
|
||||||
|
];
|
||||||
|
|
||||||
public function statusText(): Attribute
|
public function statusText(): Attribute
|
||||||
{
|
{
|
||||||
return new Attribute(
|
return new Attribute(
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ class PluginRepository extends BaseRepository
|
|||||||
|
|
||||||
public function doInstall(Plugin $plugin)
|
public function doInstall(Plugin $plugin)
|
||||||
{
|
{
|
||||||
|
$plugin->update(['status' => Plugin::STATUS_INSTALLING]);
|
||||||
$packageName = $plugin->package_name;
|
$packageName = $plugin->package_name;
|
||||||
try {
|
try {
|
||||||
$this->execComposerConfig($plugin);
|
$this->execComposerConfig($plugin);
|
||||||
@@ -72,6 +73,7 @@ class PluginRepository extends BaseRepository
|
|||||||
|
|
||||||
public function doDelete(Plugin $plugin)
|
public function doDelete(Plugin $plugin)
|
||||||
{
|
{
|
||||||
|
$plugin->update(['status' => Plugin::STATUS_DELETING]);
|
||||||
$packageName = $plugin->package_name;
|
$packageName = $plugin->package_name;
|
||||||
$removeSuccess = true;
|
$removeSuccess = true;
|
||||||
try {
|
try {
|
||||||
@@ -101,6 +103,7 @@ class PluginRepository extends BaseRepository
|
|||||||
|
|
||||||
public function doUpdate(Plugin $plugin)
|
public function doUpdate(Plugin $plugin)
|
||||||
{
|
{
|
||||||
|
$plugin->update(['status' => Plugin::STATUS_UPDATING]);
|
||||||
$packageName = $plugin->package_name;
|
$packageName = $plugin->package_name;
|
||||||
try {
|
try {
|
||||||
$output = $this->execComposerUpdate($plugin);
|
$output = $this->execComposerUpdate($plugin);
|
||||||
|
|||||||
@@ -111,42 +111,8 @@ class SearchBoxRepository extends BaseRepository
|
|||||||
*/
|
*/
|
||||||
public function migrateToModeRelated()
|
public function migrateToModeRelated()
|
||||||
{
|
{
|
||||||
$secondIconTable = 'secondicons';
|
|
||||||
$normalId = Setting::get('main.browsecat');
|
|
||||||
$specialId = Setting::get('main.specialcat');
|
|
||||||
$searchBoxList = SearchBox::query()->get();
|
$searchBoxList = SearchBox::query()->get();
|
||||||
$tables = array_values(SearchBox::$taxonomies);
|
|
||||||
|
|
||||||
foreach ($searchBoxList as $searchBox) {
|
foreach ($searchBoxList as $searchBox) {
|
||||||
// if ($searchBox->id == $normalId) {
|
|
||||||
// //all sub categories add `mode` field
|
|
||||||
// foreach ($tables as $table) {
|
|
||||||
// NexusDB::table($table)->update(['mode' => $normalId]);
|
|
||||||
// do_log("update table $table mode = $normalId");
|
|
||||||
// }
|
|
||||||
// //also second icons
|
|
||||||
// NexusDB::table($secondIconTable)->update(['mode' => $normalId]);
|
|
||||||
// do_log("update table $secondIconTable mode = $normalId");
|
|
||||||
// } elseif ($searchBox->id == $specialId && $specialId != $normalId) {
|
|
||||||
// //copy from normal section
|
|
||||||
// foreach ($tables as $table) {
|
|
||||||
// $sql = sprintf(
|
|
||||||
// "insert into `%s` (name, sort_index, mode) select name, sort_index, '%s' from `%s`",
|
|
||||||
// $table, $specialId, $table
|
|
||||||
// );
|
|
||||||
// NexusDB::statement($sql);
|
|
||||||
// do_log("copy table $table, $sql");
|
|
||||||
// }
|
|
||||||
// $fields = array_keys(SearchBox::$taxonomies);
|
|
||||||
// $fields = array_merge($fields, ['name', 'class_name', 'image']);
|
|
||||||
// $fieldStr = implode(', ', $fields);
|
|
||||||
// $sql = sprintf(
|
|
||||||
// "insert into `%s` (%s, mode) select %s, '%s' from `%s`",
|
|
||||||
// $secondIconTable, $fieldStr, $fieldStr, $specialId, $secondIconTable
|
|
||||||
// );
|
|
||||||
// NexusDB::statement($sql);
|
|
||||||
// do_log("copy table $secondIconTable, $sql");
|
|
||||||
// }
|
|
||||||
$taxonomies = [];
|
$taxonomies = [];
|
||||||
foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTable) {
|
foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTable) {
|
||||||
$searchBoxField = "show" . $torrentField;
|
$searchBoxField = "show" . $torrentField;
|
||||||
@@ -164,6 +130,7 @@ class SearchBoxRepository extends BaseRepository
|
|||||||
if (!empty($taxonomies)) {
|
if (!empty($taxonomies)) {
|
||||||
$searchBox->update(["extra->" . SearchBox::EXTRA_TAXONOMY_LABELS => $taxonomies]);
|
$searchBox->update(["extra->" . SearchBox::EXTRA_TAXONOMY_LABELS => $taxonomies]);
|
||||||
}
|
}
|
||||||
|
clear_search_box_cache($searchBox->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -200,7 +200,7 @@ return [
|
|||||||
'max_content_width' => null,
|
'max_content_width' => null,
|
||||||
'notifications' => [
|
'notifications' => [
|
||||||
'vertical_alignment' => 'top',
|
'vertical_alignment' => 'top',
|
||||||
'alignment' => 'center',
|
'alignment' => 'right',
|
||||||
],
|
],
|
||||||
'sidebar' => [
|
'sidebar' => [
|
||||||
'is_collapsible_on_desktop' => true,
|
'is_collapsible_on_desktop' => true,
|
||||||
|
|||||||
+1
-1
@@ -65,7 +65,7 @@ return [
|
|||||||
'redis' => [
|
'redis' => [
|
||||||
'driver' => 'redis',
|
'driver' => 'redis',
|
||||||
'connection' => 'default',
|
'connection' => 'default',
|
||||||
'queue' => env('REDIS_QUEUE', 'default'),
|
'queue' => env('REDIS_QUEUE', 'nexus_queue'),
|
||||||
'retry_after' => 90,
|
'retry_after' => 90,
|
||||||
'block_for' => null,
|
'block_for' => null,
|
||||||
'after_commit' => true,
|
'after_commit' => true,
|
||||||
|
|||||||
@@ -17,9 +17,11 @@ return new class extends Migration
|
|||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
foreach (self::$tables as $table) {
|
foreach (self::$tables as $table) {
|
||||||
Schema::table($table, function (Blueprint $table) {
|
if (!\Nexus\Database\NexusDB::hasColumn($table, 'mode')) {
|
||||||
$table->integer('mode')->default(0);
|
Schema::table($table, function (Blueprint $table) {
|
||||||
});
|
$table->integer('mode')->default(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,11 @@ return new class extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
Schema::table('searchbox', function (Blueprint $table) {
|
if (!\Nexus\Database\NexusDB::hasColumn('searchbox', 'section_name')) {
|
||||||
$table->json('section_name')->after('name')->nullable(true);
|
Schema::table('searchbox', function (Blueprint $table) {
|
||||||
});
|
$table->json('section_name')->after('name')->nullable(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+76
-46
@@ -261,42 +261,60 @@ function docleanup($forceAll = 0, $printProgress = false) {
|
|||||||
printProgress($log);
|
printProgress($log);
|
||||||
}
|
}
|
||||||
//11.calculate seeding bonus
|
//11.calculate seeding bonus
|
||||||
$res = sql_query("SELECT DISTINCT userid FROM peers WHERE seeder = 'yes'") or sqlerr(__FILE__, __LINE__);
|
// $res = sql_query("SELECT DISTINCT userid FROM peers WHERE seeder = 'yes'") or sqlerr(__FILE__, __LINE__);
|
||||||
if (mysql_num_rows($res) > 0)
|
// if (mysql_num_rows($res) > 0)
|
||||||
{
|
// {
|
||||||
$haremAdditionFactor = get_setting('bonus.harem_addition');
|
// $haremAdditionFactor = get_setting('bonus.harem_addition');
|
||||||
$officialAdditionFactor = get_setting('bonus.official_addition');
|
// $officialAdditionFactor = get_setting('bonus.official_addition');
|
||||||
while ($arr = mysql_fetch_assoc($res)) //loop for different users
|
// while ($arr = mysql_fetch_assoc($res)) //loop for different users
|
||||||
{
|
// {
|
||||||
$userInfo = get_user_row($arr['userid']);
|
// $userInfo = get_user_row($arr['userid']);
|
||||||
$isDonor = is_donor($userInfo);
|
// $isDonor = is_donor($userInfo);
|
||||||
$seedBonusResult = calculate_seed_bonus($arr['userid']);
|
// $seedBonusResult = calculate_seed_bonus($arr['userid']);
|
||||||
$bonusLog = "[CLEANUP_CALCULATE_SEED_BONUS], user: {$arr['userid']}, seedBonusResult: " . nexus_json_encode($seedBonusResult);
|
// $bonusLog = "[CLEANUP_CALCULATE_SEED_BONUS], user: {$arr['userid']}, seedBonusResult: " . nexus_json_encode($seedBonusResult);
|
||||||
$all_bonus = $seedBonusResult['seed_bonus'];
|
// $all_bonus = $seedBonusResult['seed_bonus'];
|
||||||
$bonusLog .= ", all_bonus: $all_bonus";
|
// $bonusLog .= ", all_bonus: $all_bonus";
|
||||||
if ($isDonor) {
|
// if ($isDonor) {
|
||||||
$all_bonus = $all_bonus * $donortimes_bonus;
|
// $all_bonus = $all_bonus * $donortimes_bonus;
|
||||||
$bonusLog .= ", isDonor, donortimes_bonus: $donortimes_bonus, all_bonus: $all_bonus";
|
// $bonusLog .= ", isDonor, donortimes_bonus: $donortimes_bonus, all_bonus: $all_bonus";
|
||||||
}
|
// }
|
||||||
if ($officialAdditionFactor > 0) {
|
// if ($officialAdditionFactor > 0) {
|
||||||
$officialAddition = $seedBonusResult['official_bonus'] * $officialAdditionFactor;
|
// $officialAddition = $seedBonusResult['official_bonus'] * $officialAdditionFactor;
|
||||||
$all_bonus += $officialAddition;
|
// $all_bonus += $officialAddition;
|
||||||
$bonusLog .= ", officialAdditionFactor: $officialAdditionFactor, official_bonus: {$seedBonusResult['official_bonus']}, officialAddition: $officialAddition, all_bonus: $all_bonus";
|
// $bonusLog .= ", officialAdditionFactor: $officialAdditionFactor, official_bonus: {$seedBonusResult['official_bonus']}, officialAddition: $officialAddition, all_bonus: $all_bonus";
|
||||||
}
|
// }
|
||||||
if ($haremAdditionFactor > 0) {
|
// if ($haremAdditionFactor > 0) {
|
||||||
$haremBonus = calculate_harem_addition($arr['userid']);
|
// $haremBonus = calculate_harem_addition($arr['userid']);
|
||||||
$haremAddition = $haremBonus * $haremAdditionFactor;
|
// $haremAddition = $haremBonus * $haremAdditionFactor;
|
||||||
$all_bonus += $haremAddition;
|
// $all_bonus += $haremAddition;
|
||||||
$bonusLog .= ", haremAdditionFactor: $haremAdditionFactor, haremBonus: $haremBonus, haremAddition: $haremAddition, all_bonus: $all_bonus";
|
// $bonusLog .= ", haremAdditionFactor: $haremAdditionFactor, haremBonus: $haremBonus, haremAddition: $haremAddition, all_bonus: $all_bonus";
|
||||||
}
|
// }
|
||||||
$dividend = 3600 / $autoclean_interval_one;
|
// $dividend = 3600 / $autoclean_interval_one;
|
||||||
$all_bonus = $all_bonus / $dividend;
|
// $all_bonus = $all_bonus / $dividend;
|
||||||
$seed_points = $seedBonusResult['seed_points'] / $dividend;
|
// $seed_points = $seedBonusResult['seed_points'] / $dividend;
|
||||||
$sql = "update users set seed_points = ifnull(seed_points, 0) + $seed_points, seedbonus = seedbonus + $all_bonus where id = {$arr["userid"]}";
|
// $sql = "update users set seed_points = ifnull(seed_points, 0) + $seed_points, seedbonus = seedbonus + $all_bonus where id = {$arr["userid"]}";
|
||||||
do_log("$bonusLog, query: $sql");
|
// do_log("$bonusLog, query: $sql");
|
||||||
sql_query($sql);
|
// sql_query($sql);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
//chunk async
|
||||||
|
$maxUidRes = mysql_fetch_assoc(sql_query("select max(id) as max_uid from users limit 1"));
|
||||||
|
$maxUid = $maxUidRes['max_uid'];
|
||||||
|
$phpPath = nexus_env('PHP_PATH', 'php');
|
||||||
|
$webRoot = rtrim(ROOT_PATH, '/');
|
||||||
|
$chunk = 2000;
|
||||||
|
$beginUid = 0;
|
||||||
|
do {
|
||||||
|
$command = sprintf(
|
||||||
|
'%s %s/artisan cleanup --action=seed_bonus --begin_uid=%s --end_uid=%s',
|
||||||
|
$phpPath, $webRoot, $beginUid, $beginUid + $chunk
|
||||||
|
);
|
||||||
|
$result = exec("$command 2>&1", $output, $result_code);
|
||||||
|
do_log(sprintf('command: %s, result_code: %s, result: %s, output: %s', $command, $result_code, $result, json_encode($output)));
|
||||||
|
$beginUid += $chunk;
|
||||||
|
} while ($beginUid < $maxUid);
|
||||||
|
|
||||||
$log = 'calculate seeding bonus';
|
$log = 'calculate seeding bonus';
|
||||||
do_log($log);
|
do_log($log);
|
||||||
if ($printProgress) {
|
if ($printProgress) {
|
||||||
@@ -810,18 +828,30 @@ function docleanup($forceAll = 0, $printProgress = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//17.update total seeding and leeching time of users
|
//17.update total seeding and leeching time of users
|
||||||
$res = sql_query("SELECT id FROM users where enabled = 'yes' and status = 'confirmed'") or sqlerr(__FILE__, __LINE__);
|
// $res = sql_query("SELECT id FROM users where enabled = 'yes' and status = 'confirmed'") or sqlerr(__FILE__, __LINE__);
|
||||||
while($arr = mysql_fetch_assoc($res))
|
// while($arr = mysql_fetch_assoc($res))
|
||||||
{
|
// {
|
||||||
//die("s" . $arr['id']);
|
// //die("s" . $arr['id']);
|
||||||
$res2 = sql_query("SELECT SUM(seedtime) as st, SUM(leechtime) as lt FROM snatched where userid = " . $arr['id'] . " LIMIT 1") or sqlerr(__FILE__, __LINE__);
|
// $res2 = sql_query("SELECT SUM(seedtime) as st, SUM(leechtime) as lt FROM snatched where userid = " . $arr['id'] . " LIMIT 1") or sqlerr(__FILE__, __LINE__);
|
||||||
$arr2 = mysql_fetch_assoc($res2) or sqlerr(__FILE__, __LINE__);
|
// $arr2 = mysql_fetch_assoc($res2) or sqlerr(__FILE__, __LINE__);
|
||||||
|
//
|
||||||
|
// //die("ss" . $arr2['st']);
|
||||||
|
// //die("sss" . "UPDATE users SET seedtime = " . $arr2['st'] . ", leechtime = " . $arr2['lt'] . " WHERE id = " . $arr['id']);
|
||||||
|
//
|
||||||
|
// sql_query("UPDATE users SET seedtime = " . intval($arr2['st']) . ", leechtime = " . intval($arr2['lt']) . " WHERE id = " . $arr['id']) or sqlerr(__FILE__, __LINE__);
|
||||||
|
// }
|
||||||
|
|
||||||
//die("ss" . $arr2['st']);
|
$beginUid = 0;
|
||||||
//die("sss" . "UPDATE users SET seedtime = " . $arr2['st'] . ", leechtime = " . $arr2['lt'] . " WHERE id = " . $arr['id']);
|
do {
|
||||||
|
$command = sprintf(
|
||||||
|
'%s %s/artisan cleanup --action=seeding_leeching_time --begin_uid=%s --end_uid=%s',
|
||||||
|
$phpPath, $webRoot, $beginUid, $beginUid + $chunk
|
||||||
|
);
|
||||||
|
$result = exec("$command 2>&1", $output, $result_code);
|
||||||
|
do_log(sprintf('command: %s, result_code: %s, result: %s, output: %s', $command, $result_code, $result, json_encode($output)));
|
||||||
|
$beginUid += $chunk;
|
||||||
|
} while ($beginUid < $maxUid);
|
||||||
|
|
||||||
sql_query("UPDATE users SET seedtime = " . intval($arr2['st']) . ", leechtime = " . intval($arr2['lt']) . " WHERE id = " . $arr['id']) or sqlerr(__FILE__, __LINE__);
|
|
||||||
}
|
|
||||||
$log = "update total seeding and leeching time of users";
|
$log = "update total seeding and leeching time of users";
|
||||||
do_log($log);
|
do_log($log);
|
||||||
if ($printProgress) {
|
if ($printProgress) {
|
||||||
|
|||||||
+7
-14
@@ -24,19 +24,12 @@ if (isset($_SERVER['argv'][1])) {
|
|||||||
}
|
}
|
||||||
$logPrefix = "[CLEANUP_CLI]";
|
$logPrefix = "[CLEANUP_CLI]";
|
||||||
$begin = time();
|
$begin = time();
|
||||||
try {
|
if ($force) {
|
||||||
if ($force) {
|
$result = docleanup(1, true);
|
||||||
$result = docleanup(1, true);
|
} else {
|
||||||
} else {
|
$result = autoclean(true);
|
||||||
$result = autoclean(true);
|
|
||||||
}
|
|
||||||
$log = "$logPrefix, DONE: $result, cost time in seconds: " . (time() - $begin);
|
|
||||||
do_log($log);
|
|
||||||
printProgress($log);
|
|
||||||
} catch (\Exception $exception) {
|
|
||||||
$log = "$logPrefix, ERROR: " . $exception->getMessage();
|
|
||||||
do_log($log);
|
|
||||||
printProgress($log);
|
|
||||||
throw new \RuntimeException($exception->getMessage());
|
|
||||||
}
|
}
|
||||||
|
$log = "$logPrefix, DONE: $result, cost time in seconds: " . (time() - $begin);
|
||||||
|
do_log($log);
|
||||||
|
printProgress($log);
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ use App\Models\UserBanLog;
|
|||||||
use App\Repositories\AttendanceRepository;
|
use App\Repositories\AttendanceRepository;
|
||||||
use App\Repositories\BonusRepository;
|
use App\Repositories\BonusRepository;
|
||||||
use App\Repositories\ExamRepository;
|
use App\Repositories\ExamRepository;
|
||||||
|
use App\Repositories\SearchBoxRepository;
|
||||||
use App\Repositories\TagRepository;
|
use App\Repositories\TagRepository;
|
||||||
use App\Repositories\ToolRepository;
|
use App\Repositories\ToolRepository;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
@@ -255,6 +256,18 @@ class Update extends Install
|
|||||||
]]);
|
]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.8.0
|
||||||
|
*/
|
||||||
|
if (!NexusDB::hasColumn('searchbox', 'section_name')) {
|
||||||
|
$this->runMigrate('database/migrations/2022_09_05_230532_add_mode_to_section_related.php');
|
||||||
|
$this->runMigrate('database/migrations/2022_09_06_004318_add_section_name_to_searchbox_table.php');
|
||||||
|
$this->runMigrate('database/migrations/2022_09_06_030324_change_searchbox_field_extra_to_json.php');
|
||||||
|
$searchBoxRep = new SearchBoxRepository();
|
||||||
|
$searchBoxRep->migrateToModeRelated();
|
||||||
|
$this->doLog("[MIGRATE_TAXONOMY_TO_MODE_RELATED]");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function runExtraMigrate()
|
public function runExtraMigrate()
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ return [
|
|||||||
'remote_url' => '仓库地址',
|
'remote_url' => '仓库地址',
|
||||||
'installed_version' => '已安装版本',
|
'installed_version' => '已安装版本',
|
||||||
'status' => '状态',
|
'status' => '状态',
|
||||||
|
'updated_at' => '上次执行操作',
|
||||||
],
|
],
|
||||||
'status' => [
|
'status' => [
|
||||||
\App\Models\Plugin::STATUS_NORMAL => '正常',
|
\App\Models\Plugin::STATUS_NORMAL => '正常',
|
||||||
|
|||||||
Reference in New Issue
Block a user