Skip to content

Commit

Permalink
Remove debug performance tracing for logging movie
Browse files Browse the repository at this point in the history
  • Loading branch information
leepeuker committed Dec 8, 2023
1 parent 8690683 commit cdc06fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
15 changes: 4 additions & 11 deletions src/HttpController/Web/HistoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
use Movary\Service\Tmdb\SyncMovie;
use Movary\Util\Json;
use Movary\ValueObject\Date;
use Movary\ValueObject\DateTime;
use Movary\ValueObject\Http\Request;
use Movary\ValueObject\Http\Response;
use Movary\ValueObject\Http\StatusCode;
use Movary\ValueObject\PersonalRating;
use Psr\Log\LoggerInterface;
use RuntimeException;
use Twig\Environment;

Expand All @@ -33,7 +31,6 @@ public function __construct(
private readonly Authentication $authenticationService,
private readonly UserPageAuthorizationChecker $userPageAuthorizationChecker,
private readonly PaginationElementsCalculator $paginationElementsCalculator,
private readonly LoggerInterface $logger,
) {
}

Expand All @@ -53,16 +50,17 @@ public function createHistoryEntry(Request $request) : Response
$newWatchDate = empty($requestBody['newWatchDate']) === false ? Date::createFromStringAndFormat($requestBody['newWatchDate'], $dateFormat) : null;
$originalWatchDate = empty($requestBody['originalWatchDate']) === false ? Date::createFromStringAndFormat($requestBody['originalWatchDate'], $dateFormat) : null;

$plays = (int)$requestBody['plays'];
$plays = empty($requestBody['plays']) === true ? 1 : (int)$requestBody['plays'];
$comment = empty($requestBody['comment']) === true ? null : (string)$requestBody['comment'];
$position = empty($requestBody['position']) === true ? 1 : (int)$requestBody['position'];

if ($originalWatchDate == $newWatchDate) {
$this->movieApi->replaceHistoryForMovieByDate($movieId, $userId, $newWatchDate, $plays, $comment);
$this->movieApi->replaceHistoryForMovieByDate($movieId, $userId, $newWatchDate, $plays, $position, $comment);

return Response::create(StatusCode::createNoContent());
}

$this->movieApi->addPlaysForMovieOnDate($movieId, $userId, $newWatchDate, $plays);
$this->movieApi->addPlaysForMovieOnDate($movieId, $userId, $newWatchDate, $plays, $position);
$this->movieApi->deleteHistoryByIdAndDate($movieId, $userId, $originalWatchDate);

if ($comment !== null) {
Expand Down Expand Up @@ -92,7 +90,6 @@ public function deleteHistoryEntry(Request $request) : Response

public function logMovie(Request $request) : Response
{
$this->logger->debug('CREATE_MOVIE_LOG start - ' . DateTime::create()->format('Y-m-d H:i:s.u'));
$userId = $this->authenticationService->getCurrentUserId();

$requestData = Json::decode($request->getBody());
Expand All @@ -106,9 +103,7 @@ public function logMovie(Request $request) : Response
$personalRating = $requestData['personalRating'] === 0 ? null : PersonalRating::create((int)$requestData['personalRating']);
$comment = empty($requestData['comment']) === true ? null : (string)$requestData['comment'];

$this->logger->debug('CREATE_MOVIE_LOG before local tmdb search - ' . DateTime::create()->format('Y-m-d H:i:s.u'));
$movie = $this->movieApi->findByTmdbId($tmdbId);
$this->logger->debug('CREATE_MOVIE_LOG after local tmdb search - ' . DateTime::create()->format('Y-m-d H:i:s.u'));

if ($movie === null) {
$movie = $this->tmdbMovieSyncService->syncMovie($tmdbId);
Expand All @@ -118,8 +113,6 @@ public function logMovie(Request $request) : Response
$this->movieApi->addPlaysForMovieOnDate($movie->getId(), $userId, $watchDate);
$this->movieApi->updateHistoryComment($movie->getId(), $userId, $watchDate, $comment);

$this->logger->debug('CREATE_MOVIE_LOG end - ' . DateTime::create()->format('Y-m-d H:i:s.u'));

return Response::create(StatusCode::createOk());
}

Expand Down
6 changes: 1 addition & 5 deletions src/Service/Tmdb/SyncMovie.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Movary\Domain\Movie\MovieEntity;
use Movary\JobQueue\JobQueueScheduler;
use Movary\ValueObject\Date;
use Movary\ValueObject\DateTime;
use Psr\Log\LoggerInterface;
use Throwable;

Expand All @@ -29,7 +28,6 @@ public function __construct(

public function syncMovie(int $tmdbId) : MovieEntity
{
$this->logger->debug('CREATE_MOVIE_LOG before tmdb remote fetch - ' . DateTime::create()->format('Y-m-d H:i:s.u'));
try {
$tmdbMovie = $this->tmdbApi->fetchMovieDetails($tmdbId);
} catch (Throwable) {
Expand All @@ -39,8 +37,6 @@ public function syncMovie(int $tmdbId) : MovieEntity
$tmdbMovie = $this->tmdbApi->fetchMovieDetails($tmdbId);
}

$this->logger->debug('CREATE_MOVIE_LOG after tmdb remote fetch - ' . DateTime::create()->format('Y-m-d H:i:s.u'));

$movie = $this->movieApi->findByTmdbId($tmdbId);

$this->dbConnection->beginTransaction();
Expand All @@ -55,7 +51,7 @@ public function syncMovie(int $tmdbId) : MovieEntity
tagline: $tmdbMovie->getTagline(),
overview: $tmdbMovie->getOverview(),
originalLanguage: $tmdbMovie->getOriginalLanguage(),
releaseDate: $tmdbMovie->getReleaseDate()?->asDate(),
releaseDate: Date::createFromDateTime($tmdbMovie->getReleaseDate()),
runtime: $tmdbMovie->getRuntime(),
tmdbVoteAverage: $tmdbMovie->getVoteAverage(),
tmdbVoteCount: $tmdbMovie->getVoteCount(),
Expand Down

0 comments on commit cdc06fb

Please sign in to comment.