Skip to content

Commit

Permalink
delete old torrent form templates
Browse files Browse the repository at this point in the history
  • Loading branch information
pjc09h committed May 31, 2024
1 parent 2411511 commit 54a35dd
Show file tree
Hide file tree
Showing 52 changed files with 683 additions and 2,458 deletions.
1 change: 1 addition & 0 deletions app/Models/ObjectCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ private function loadRelationships($object): void

$this->relationships->{$object::$type} ??= null;
if (!$this->relationships->{$object::$type}) {
$this->relationships->{$object::$type} = [];
return;
}

Expand Down
24 changes: 24 additions & 0 deletions app/Models/TorrentGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public function delete(): void
public function relationships(): ?array
{
return [
Collages::$type => $this->relatedCollages(),
Creators::$type => $this->relatedCreators(),
Literature::$type => $this->relatedLiterature(),
Tags::$type => $this->relatedTags(),
Expand All @@ -155,6 +156,29 @@ public function relationships(): ?array
}


/**
* relatedCollages
*/
private function relatedCollages(): ?array
{
$app = App::go();

$query = "select collageId from collages_torrents where groupId = ?";
$ref = $app->dbNew->column($query, [$this->id]);

if (!$ref) {
return null;
}

$data = [];
foreach ($ref as $row) {
$data[] = ["id" => $row, "type" => Collages::$type];
}

return $data;
}


/**
* relatedCreators
*/
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Torrents.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function read(int|string $id = null): void
parent::read($id);

# explode the fileList
$fileList = explode("÷", $this->attributes->fileList);
$fileList = explode("÷", $this->attributes->fileList ?? "");
$fileData = [];

foreach ($fileList as $file) {
Expand Down
10 changes: 10 additions & 0 deletions app/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ class Permissions
"deleteAny" => "Can delete any creators",
],

# literature
"literature" => [
"create" => "Can create literature",
"read" => "Can read literature",
"updateOwn" => "Can update own literature",
"updateAny" => "Can update any literature",
"deleteOwn" => "Can delete own literature",
"deleteAny" => "Can delete any literature",
],

# requests
"requests" => [
"create" => "Can create requests",
Expand Down
97 changes: 73 additions & 24 deletions app/Top10.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,22 @@ public static function dailyTorrents(int $limit = null): ?array
$cacheHit = $app->cache->get($cacheKey);

if ($cacheHit) {
return $cacheHit;
#return $cacheHit;
}

# set limit and query extras
$limit ??= self::$defaultLimit;
$query = self::$torrentQuery . "where torrents.created_at > (now() - interval 1 day) order by (torrents.seeders + torrents.leechers) desc limit :limit";
$ref = $app->dbNew->multi($query, ["limit" => $limit]);

$app->cache->set($cacheKey, $ref, self::$cacheDuration);
return $ref;
$data = [];
foreach ($ref as $key => $row) {
$data[] = new TorrentGroups($row["id"]);
$data[$key]->attributes->dataTransfer = $row["dataTransfer"];
}

$app->cache->set($cacheKey, $data, self::$cacheDuration);
return $data;
}


Expand All @@ -128,16 +134,22 @@ public static function weeklyTorrents(int $limit = null): ?array
$cacheHit = $app->cache->get($cacheKey);

if ($cacheHit) {
return $cacheHit;
#return $cacheHit;
}

# set limit and query extras
$limit ??= self::$defaultLimit;
$query = self::$torrentQuery . "where torrents.created_at > (now() - interval 1 week) order by (torrents.seeders + torrents.leechers) desc limit :limit";
$ref = $app->dbNew->multi($query, ["limit" => $limit]);

$app->cache->set($cacheKey, $ref, self::$cacheDuration);
return $ref;
$data = [];
foreach ($ref as $key => $row) {
$data[] = new TorrentGroups($row["id"]);
$data[$key]->attributes->dataTransfer = $row["dataTransfer"];
}

$app->cache->set($cacheKey, $data, self::$cacheDuration);
return $data;
}


Expand All @@ -158,16 +170,22 @@ public static function monthlyTorrents(int $limit = null): ?array
$cacheHit = $app->cache->get($cacheKey);

if ($cacheHit) {
return $cacheHit;
#return $cacheHit;
}

# set limit and query extras
$limit ??= self::$defaultLimit;
$query = self::$torrentQuery . "where torrents.created_at > (now() - interval 1 month) order by (torrents.seeders + torrents.leechers) desc limit :limit";
$ref = $app->dbNew->multi($query, ["limit" => $limit]);

$app->cache->set($cacheKey, $ref, self::$cacheDuration);
return $ref;
$data = [];
foreach ($ref as $key => $row) {
$data[] = new TorrentGroups($row["id"]);
$data[$key]->attributes->dataTransfer = $row["dataTransfer"];
}

$app->cache->set($cacheKey, $data, self::$cacheDuration);
return $data;
}


Expand All @@ -188,18 +206,25 @@ public static function yearlyTorrents(int $limit = null): ?array
$cacheHit = $app->cache->get($cacheKey);

if ($cacheHit) {
return $cacheHit;
#return $cacheHit;
}

# set limit and query extras
$limit ??= self::$defaultLimit;
$query = self::$torrentQuery . "where torrents.created_at > (now() - interval 1 year) order by (torrents.seeders + torrents.leechers) desc limit :limit";
$ref = $app->dbNew->multi($query, ["limit" => $limit]);

$app->cache->set($cacheKey, $ref, self::$cacheDuration);
return $ref;
$data = [];
foreach ($ref as $key => $row) {
$data[] = new TorrentGroups($row["id"]);
$data[$key]->attributes->dataTransfer = $row["dataTransfer"];
}

$app->cache->set($cacheKey, $data, self::$cacheDuration);
return $data;
}


/**
* overallTorrents
*
Expand All @@ -217,16 +242,22 @@ public static function overallTorrents(int $limit = null): ?array
$cacheHit = $app->cache->get($cacheKey);

if ($cacheHit) {
return $cacheHit;
#return $cacheHit;
}

# set limit and query extras
$limit ??= self::$defaultLimit;
$query = self::$torrentQuery . "order by (torrents.seeders + torrents.leechers) desc limit :limit";
$ref = $app->dbNew->multi($query, ["limit" => $limit]);

$app->cache->set($cacheKey, $ref, self::$cacheDuration);
return $ref;
$data = [];
foreach ($ref as $key => $row) {
$data[] = new TorrentGroups($row["id"]);
$data[$key]->attributes->dataTransfer = $row["dataTransfer"];
}

$app->cache->set($cacheKey, $data, self::$cacheDuration);
return $data;
}


Expand All @@ -247,16 +278,22 @@ public static function torrentSeeders(int $limit = null): ?array
$cacheHit = $app->cache->get($cacheKey);

if ($cacheHit) {
return $cacheHit;
#return $cacheHit;
}

# set limit and query extras
$limit ??= self::$defaultLimit;
$query = self::$torrentQuery . "order by torrents.seeders desc limit :limit";
$ref = $app->dbNew->multi($query, ["limit" => $limit]);

$app->cache->set($cacheKey, $ref, self::$cacheDuration);
return $ref;
$data = [];
foreach ($ref as $key => $row) {
$data[] = new TorrentGroups($row["id"]);
$data[$key]->attributes->dataTransfer = $row["dataTransfer"];
}

$app->cache->set($cacheKey, $data, self::$cacheDuration);
return $data;
}


Expand All @@ -277,16 +314,22 @@ public static function torrentSnatches(int $limit = null): ?array
$cacheHit = $app->cache->get($cacheKey);

if ($cacheHit) {
return $cacheHit;
#return $cacheHit;
}

# set limit and query extras
$limit ??= self::$defaultLimit;
$query = self::$torrentQuery . "order by torrents.snatched desc limit :limit";
$ref = $app->dbNew->multi($query, ["limit" => $limit]);

$app->cache->set($cacheKey, $ref, self::$cacheDuration);
return $ref;
$data = [];
foreach ($ref as $key => $row) {
$data[] = new TorrentGroups($row["id"]);
$data[$key]->attributes->dataTransfer = $row["dataTransfer"];
}

$app->cache->set($cacheKey, $data, self::$cacheDuration);
return $data;
}


Expand All @@ -307,16 +350,22 @@ public static function torrentData(int $limit = null): ?array
$cacheHit = $app->cache->get($cacheKey);

if ($cacheHit) {
return $cacheHit;
#return $cacheHit;
}

# set limit and query extras
$limit ??= self::$defaultLimit;
$query = self::$torrentQuery . "order by dataTransfer desc limit :limit";
$ref = $app->dbNew->multi($query, ["limit" => $limit]);

$app->cache->set($cacheKey, $ref, self::$cacheDuration);
return $ref;
$data = [];
foreach ($ref as $key => $row) {
$data[] = new TorrentGroups($row["id"]);
$data[$key]->attributes->dataTransfer = $row["dataTransfer"];
}

$app->cache->set($cacheKey, $data, self::$cacheDuration);
return $data;
}


Expand Down
Loading

0 comments on commit 54a35dd

Please sign in to comment.