mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2026-04-01 01:25:39 +00:00
make common methods optimization
This commit is contained in:
parent
8d258c677b
commit
285a5104e2
10 changed files with 91 additions and 201 deletions
|
|
@ -21,23 +21,6 @@ class TorrentDownloadFileRepository extends ServiceEntityRepository
|
|||
parent::__construct($registry, TorrentDownloadFile::class);
|
||||
}
|
||||
|
||||
public function findTorrentDownloadFile(
|
||||
int $torrentId,
|
||||
int $userId
|
||||
): ?TorrentDownloadFile
|
||||
{
|
||||
return $this->createQueryBuilder('tdf')
|
||||
->where('tdf.torrentId = :torrentId')
|
||||
->andWhere('tdf.userId = :userId')
|
||||
->setParameter('torrentId', $torrentId)
|
||||
->setParameter('userId', $userId)
|
||||
->orderBy('tdf.id', 'DESC') // same to ts.added
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function findTorrentDownloadFilesTotalByTorrentId(
|
||||
int $torrentId
|
||||
): int
|
||||
|
|
|
|||
|
|
@ -21,23 +21,6 @@ class TorrentDownloadMagnetRepository extends ServiceEntityRepository
|
|||
parent::__construct($registry, TorrentDownloadMagnet::class);
|
||||
}
|
||||
|
||||
public function findTorrentDownloadMagnet(
|
||||
int $torrentId,
|
||||
int $userId
|
||||
): ?TorrentDownloadMagnet
|
||||
{
|
||||
return $this->createQueryBuilder('tdm')
|
||||
->where('tdm.torrentId = :torrentId')
|
||||
->andWhere('tdm.userId = :userId')
|
||||
->setParameter('torrentId', $torrentId)
|
||||
->setParameter('userId', $userId)
|
||||
->orderBy('tdm.id', 'DESC') // same to ts.added
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function findTorrentDownloadMagnetsTotalByTorrentId(
|
||||
int $torrentId
|
||||
): int
|
||||
|
|
|
|||
|
|
@ -20,37 +20,4 @@ class TorrentLocalesRepository extends ServiceEntityRepository
|
|||
{
|
||||
parent::__construct($registry, TorrentLocales::class);
|
||||
}
|
||||
|
||||
public function getTorrentLocales(int $id): ?TorrentLocales
|
||||
{
|
||||
return $this->createQueryBuilder('tl')
|
||||
->where('tl.id = :id')
|
||||
->setParameter('id', $id)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function findLastTorrentLocalesByTorrentId(int $torrentId): ?TorrentLocales
|
||||
{
|
||||
return $this->createQueryBuilder('tl')
|
||||
->where('tl.torrentId = :torrentId')
|
||||
->setParameter('torrentId', $torrentId)
|
||||
->orderBy('tl.id', 'DESC') // same to tl.added
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function findTorrentLocalesByTorrentId(int $torrentId): array
|
||||
{
|
||||
return $this->createQueryBuilder('tl')
|
||||
->where('tl.torrentId = :torrentId')
|
||||
->setParameter('torrentId', $torrentId)
|
||||
->orderBy('tl.id', 'DESC') // same to tl.added
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,24 +20,4 @@ class TorrentRepository extends ServiceEntityRepository
|
|||
{
|
||||
parent::__construct($registry, Torrent::class);
|
||||
}
|
||||
|
||||
public function getTorrent(int $id): ?Torrent
|
||||
{
|
||||
return $this->createQueryBuilder('t')
|
||||
->where('t.id = :id')
|
||||
->setParameter('id', $id)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function getTorrentScrapeQueue(): ?Torrent
|
||||
{
|
||||
return $this->createQueryBuilder('t')
|
||||
->orderBy('t.scraped', 'ASC') // same to ts.added
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,37 +20,4 @@ class TorrentSensitiveRepository extends ServiceEntityRepository
|
|||
{
|
||||
parent::__construct($registry, TorrentSensitive::class);
|
||||
}
|
||||
|
||||
public function getTorrentSensitive(int $id): ?TorrentSensitive
|
||||
{
|
||||
return $this->createQueryBuilder('ts')
|
||||
->where('ts.id = :id')
|
||||
->setParameter('id', $id)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function findLastTorrentSensitiveByTorrentId(int $torrentId): ?TorrentSensitive
|
||||
{
|
||||
return $this->createQueryBuilder('ts')
|
||||
->where('ts.torrentId = :torrentId')
|
||||
->setParameter('torrentId', $torrentId)
|
||||
->orderBy('ts.id', 'DESC') // same to ts.added
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function findTorrentSensitiveByTorrentId(int $torrentId): array
|
||||
{
|
||||
return $this->createQueryBuilder('ts')
|
||||
->where('ts.torrentId = :torrentId')
|
||||
->setParameter('torrentId', $torrentId)
|
||||
->orderBy('ts.id', 'DESC') // same to ts.added
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,30 +21,13 @@ class TorrentStarRepository extends ServiceEntityRepository
|
|||
parent::__construct($registry, TorrentStar::class);
|
||||
}
|
||||
|
||||
public function findTorrentStar(
|
||||
int $torrentId,
|
||||
int $userId
|
||||
): ?TorrentStar
|
||||
{
|
||||
return $this->createQueryBuilder('tb')
|
||||
->where('tb.torrentId = :torrentId')
|
||||
->andWhere('tb.userId = :userId')
|
||||
->setParameter('torrentId', $torrentId)
|
||||
->setParameter('userId', $userId)
|
||||
->orderBy('tb.id', 'DESC') // same to ts.added
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function findTorrentStarsTotalByTorrentId(
|
||||
int $torrentId
|
||||
): int
|
||||
{
|
||||
return $this->createQueryBuilder('tb')
|
||||
->select('count(tb.id)')
|
||||
->where('tb.torrentId = :torrentId')
|
||||
return $this->createQueryBuilder('ts')
|
||||
->select('count(ts.id)')
|
||||
->where('ts.torrentId = :torrentId')
|
||||
->setParameter('torrentId', $torrentId)
|
||||
->getQuery()
|
||||
->getSingleScalarResult()
|
||||
|
|
|
|||
|
|
@ -20,24 +20,4 @@ class UserRepository extends ServiceEntityRepository
|
|||
{
|
||||
parent::__construct($registry, User::class);
|
||||
}
|
||||
|
||||
public function getUser(int $id): ?User
|
||||
{
|
||||
return $this->createQueryBuilder('u')
|
||||
->where('u.id = :id')
|
||||
->setParameter('id', $id)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function findOneByAddressField(string $address): ?User
|
||||
{
|
||||
return $this->createQueryBuilder('u')
|
||||
->where('u.address = :address')
|
||||
->setParameter('address', $address)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,22 +21,6 @@ class UserStarRepository extends ServiceEntityRepository
|
|||
parent::__construct($registry, UserStar::class);
|
||||
}
|
||||
|
||||
public function findUserStar(
|
||||
int $userId,
|
||||
int $userIdTarget
|
||||
): ?UserStar
|
||||
{
|
||||
return $this->createQueryBuilder('us')
|
||||
->where('us.userId = :userId')
|
||||
->andWhere('us.userIdTarget = :userIdTarget')
|
||||
->setParameter('userId', $userId)
|
||||
->setParameter('userIdTarget', $userIdTarget)
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function findUserStarsTotalByUserIdTarget(
|
||||
int $userIdTarget
|
||||
): int
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue