mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 04:20:49 +08:00
improve cleanup
This commit is contained in:
@@ -299,16 +299,18 @@ function docleanup($forceAll = 0, $printProgress = false) {
|
||||
// }
|
||||
|
||||
//chunk async
|
||||
$requestId = nexus()->getRequestId();
|
||||
$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_log("maxUid: $maxUid, chunk: $chunk");
|
||||
do {
|
||||
$command = sprintf(
|
||||
'%s %s/artisan cleanup --action=seed_bonus --begin_uid=%s --end_uid=%s',
|
||||
$phpPath, $webRoot, $beginUid, $beginUid + $chunk
|
||||
'%s %s/artisan cleanup --action=seed_bonus --begin_id=%s --end_id=%s --request_id=%s',
|
||||
$phpPath, $webRoot, $beginUid, $beginUid + $chunk, $requestId
|
||||
);
|
||||
$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)));
|
||||
@@ -366,38 +368,53 @@ function docleanup($forceAll = 0, $printProgress = false) {
|
||||
}
|
||||
|
||||
//4.update count of seeders, leechers, comments for torrents
|
||||
$torrents = array();
|
||||
$res = sql_query("SELECT torrent, seeder, COUNT(*) AS c FROM peers GROUP BY torrent, seeder") or sqlerr(__FILE__, __LINE__);
|
||||
while ($row = mysql_fetch_assoc($res)) {
|
||||
if ($row["seeder"] == "yes")
|
||||
$key = "seeders";
|
||||
else
|
||||
$key = "leechers";
|
||||
$torrents[$row["torrent"]][$key] = $row["c"];
|
||||
}
|
||||
// $torrents = array();
|
||||
// $res = sql_query("SELECT torrent, seeder, COUNT(*) AS c FROM peers GROUP BY torrent, seeder") or sqlerr(__FILE__, __LINE__);
|
||||
// while ($row = mysql_fetch_assoc($res)) {
|
||||
// if ($row["seeder"] == "yes")
|
||||
// $key = "seeders";
|
||||
// else
|
||||
// $key = "leechers";
|
||||
// $torrents[$row["torrent"]][$key] = $row["c"];
|
||||
// }
|
||||
//
|
||||
// $res = sql_query("SELECT torrent, COUNT(*) AS c FROM comments GROUP BY torrent") or sqlerr(__FILE__, __LINE__);
|
||||
// while ($row = mysql_fetch_assoc($res)) {
|
||||
// $torrents[$row["torrent"]]["comments"] = $row["c"];
|
||||
// }
|
||||
//
|
||||
// $fields = explode(":", "comments:leechers:seeders");
|
||||
// $res = sql_query("SELECT id, seeders, leechers, comments FROM torrents") or sqlerr(__FILE__, __LINE__);
|
||||
// while ($row = mysql_fetch_assoc($res)) {
|
||||
// $id = $row["id"];
|
||||
// $torr = $torrents[$id] ?? [];
|
||||
// foreach ($fields as $field) {
|
||||
// if (!isset($torr[$field]))
|
||||
// $torr[$field] = 0;
|
||||
// }
|
||||
// $update = array();
|
||||
// foreach ($fields as $field) {
|
||||
// if ($torr[$field] != $row[$field])
|
||||
// $update[] = "$field = " . $torr[$field];
|
||||
// }
|
||||
// if (count($update))
|
||||
// sql_query("UPDATE torrents SET " . implode(",", $update) . " WHERE id = $id") or sqlerr(__FILE__, __LINE__);
|
||||
// }
|
||||
|
||||
$res = sql_query("SELECT torrent, COUNT(*) AS c FROM comments GROUP BY torrent") or sqlerr(__FILE__, __LINE__);
|
||||
while ($row = mysql_fetch_assoc($res)) {
|
||||
$torrents[$row["torrent"]]["comments"] = $row["c"];
|
||||
}
|
||||
|
||||
$fields = explode(":", "comments:leechers:seeders");
|
||||
$res = sql_query("SELECT id, seeders, leechers, comments FROM torrents") or sqlerr(__FILE__, __LINE__);
|
||||
while ($row = mysql_fetch_assoc($res)) {
|
||||
$id = $row["id"];
|
||||
$torr = $torrents[$id] ?? [];
|
||||
foreach ($fields as $field) {
|
||||
if (!isset($torr[$field]))
|
||||
$torr[$field] = 0;
|
||||
}
|
||||
$update = array();
|
||||
foreach ($fields as $field) {
|
||||
if ($torr[$field] != $row[$field])
|
||||
$update[] = "$field = " . $torr[$field];
|
||||
}
|
||||
if (count($update))
|
||||
sql_query("UPDATE torrents SET " . implode(",", $update) . " WHERE id = $id") or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
$maxTorrentIdRes = mysql_fetch_assoc(sql_query("select max(id) as max_torrent_id from torrents limit 1"));
|
||||
$maxTorrentId = $maxTorrentIdRes['max_torrent_id'];
|
||||
$chunk = 5000;
|
||||
$beginTorrentId = 0;
|
||||
do_log("maxTorrentId: $maxTorrentId, chunk: $chunk");
|
||||
do {
|
||||
$command = sprintf(
|
||||
'%s %s/artisan cleanup --action=seeders_etc --begin_id=%s --end_id=%s --request_id=%s',
|
||||
$phpPath, $webRoot, $beginTorrentId, $beginTorrentId + $chunk, $requestId
|
||||
);
|
||||
$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)));
|
||||
$beginTorrentId += $chunk;
|
||||
} while ($beginTorrentId < $maxTorrentId);
|
||||
$log = "update count of seeders, leechers, comments for torrents";
|
||||
do_log($log);
|
||||
if ($printProgress) {
|
||||
@@ -841,11 +858,13 @@ function docleanup($forceAll = 0, $printProgress = false) {
|
||||
// sql_query("UPDATE users SET seedtime = " . intval($arr2['st']) . ", leechtime = " . intval($arr2['lt']) . " WHERE id = " . $arr['id']) or sqlerr(__FILE__, __LINE__);
|
||||
// }
|
||||
|
||||
$chunk = 2000;
|
||||
$beginUid = 0;
|
||||
do_log("maxUid: $maxUid, chunk: $chunk");
|
||||
do {
|
||||
$command = sprintf(
|
||||
'%s %s/artisan cleanup --action=seeding_leeching_time --begin_uid=%s --end_uid=%s',
|
||||
$phpPath, $webRoot, $beginUid, $beginUid + $chunk
|
||||
'%s %s/artisan cleanup --action=seeding_leeching_time --begin_id=%s --end_id=%s --request_id=%s',
|
||||
$phpPath, $webRoot, $beginUid, $beginUid + $chunk, $requestId
|
||||
);
|
||||
$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)));
|
||||
|
||||
@@ -2911,7 +2911,7 @@ function stdfoot() {
|
||||
$yearfounded = ($year ? $year : 2007);
|
||||
print(" (c) "." <a href=\"" . get_protocol_prefix() . $BASEURL."\" target=\"_self\">".$SITENAME."</a> ".($icplicense_main ? " ".$icplicense_main." " : "").(date("Y") != $yearfounded ? $yearfounded."-" : "").date("Y")." ".VERSION."<br /><br />");
|
||||
printf ("[page created in <b> %s </b> sec", sprintf("%.3f", $totaltime));
|
||||
print (", takes up <b>".mksize(memory_get_usage())."</b> ram]");
|
||||
print (" with <b>".count($query_name)."</b> db queries, <b>".$Cache->getCacheReadTimes()."</b> reads and <b>".$Cache->getCacheWriteTimes()."</b> writes of Redis and <b>".mksize(memory_get_usage())."</b> ram]");
|
||||
print ("</div>\n");
|
||||
if ($enablesqldebug_tweak == 'yes' && get_user_class() >= $sqldebug_tweak) {
|
||||
print("<div id=\"sql_debug\" style='text-align: left;'>SQL query list: <ul>");
|
||||
|
||||
@@ -986,7 +986,14 @@ function clear_setting_cache()
|
||||
{
|
||||
\Nexus\Database\NexusDB::cache_del('nexus_settings_in_laravel');
|
||||
\Nexus\Database\NexusDB::cache_del('nexus_settings_in_nexus');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see functions.php::get_category_row()
|
||||
*/
|
||||
function clear_category_cache()
|
||||
{
|
||||
\Nexus\Database\NexusDB::cache_del('category_content');
|
||||
}
|
||||
|
||||
function clear_staff_message_cache()
|
||||
|
||||
Reference in New Issue
Block a user