diff --git a/README.md b/README.md index 7008868..b9a0d14 100644 --- a/README.md +++ b/README.md @@ -55,11 +55,13 @@ ### Docker Compose mysql: image: mysql:8.0 + command: --host-cache-size=0 --innodb-use-native-aio=0 --sql-mode=STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION --log-error-verbosity=1 environment: - MYSQL_DATABASE=${DB_DATABASE} - MYSQL_USER=${DB_USERNAME} - MYSQL_PASSWORD=${DB_PASSWORD} - MYSQL_ROOT_PASSWORD=${DB_PASSWORD} + - TZ=UTC volumes: - mysql_data:/var/lib/mysql restart: unless-stopped diff --git a/app/Http/Controllers/ArticlesController.php b/app/Http/Controllers/ArticlesController.php index a93bc4c..c300a44 100644 --- a/app/Http/Controllers/ArticlesController.php +++ b/app/Http/Controllers/ArticlesController.php @@ -10,7 +10,9 @@ class ArticlesController extends Controller { public function __invoke(Request $request): View { - $articles = Article::all()->sortByDesc('created_at'); + $articles = Article::with('articlePublication') + ->orderBy('created_at', 'desc') + ->paginate(15); return view('pages.articles.index', compact('articles')); } diff --git a/app/Jobs/RefreshArticlesJob.php b/app/Jobs/RefreshArticlesJob.php index a618d68..a5ebb73 100644 --- a/app/Jobs/RefreshArticlesJob.php +++ b/app/Jobs/RefreshArticlesJob.php @@ -2,6 +2,7 @@ namespace App\Jobs; +use App\Services\Article\ArticleFetcher; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Queue\Queueable; @@ -9,24 +10,13 @@ class RefreshArticlesJob implements ShouldQueue { use Queueable; - /** - * Create a new job instance. - */ public function __construct() { $this->onQueue('lemmy-posts'); } - /** - * Execute the job. - */ public function handle(): void { - echo "Starting article refresh job...\n"; - - // Call the article refresh command - \Artisan::call('article:refresh'); - - echo "Article refresh job completed!\n"; + ArticleFetcher::getNewArticles(); } } diff --git a/app/Models/Article.php b/app/Models/Article.php index 9d4f9c7..55430c4 100644 --- a/app/Models/Article.php +++ b/app/Models/Article.php @@ -12,6 +12,8 @@ /** * @method static firstOrCreate(string[] $array) + * @method static where(string $string, string $url) + * @method static create(string[] $array) * @property integer $id * @property string $url * @property bool|null $is_valid @@ -73,7 +75,6 @@ public function articlePublications(): HasMany protected static function booted(): void { static::created(function ($article) { - echo "Article::created event fired for article ID {$article->id}\n"; event(new ArticleFetched($article)); }); } diff --git a/app/Services/Article/ArticleFetcher.php b/app/Services/Article/ArticleFetcher.php index 011acaa..19e08ef 100644 --- a/app/Services/Article/ArticleFetcher.php +++ b/app/Services/Article/ArticleFetcher.php @@ -29,6 +29,7 @@ public static function getNewArticles(): Collection return $allArticles->filter(); } catch (Exception $e) { logger()->error("Failed to get new articles", ['error' => $e->getMessage()]); + return new Collection([]); } } @@ -45,6 +46,7 @@ public static function fetchArticleData(Article $article): array 'url' => $article->url, 'error' => $e->getMessage() ]); + return []; } } @@ -52,13 +54,11 @@ public static function fetchArticleData(Article $article): array private static function saveArticle(string $url): Article { $existingArticle = Article::where('url', $url)->first(); - + if ($existingArticle) { - echo "ArticleFetcher: Found existing article ID {$existingArticle->id} for URL: {$url}\n"; return $existingArticle; } - - echo "ArticleFetcher: Creating new article for URL: {$url}\n"; + return Article::create(['url' => $url]); } } diff --git a/app/Services/Auth/LemmyAuthService.php b/app/Services/Auth/LemmyAuthService.php index b70a4c1..d76aee8 100644 --- a/app/Services/Auth/LemmyAuthService.php +++ b/app/Services/Auth/LemmyAuthService.php @@ -32,7 +32,8 @@ public static function getToken(): string throw new PlatformAuthException(PlatformEnum::LEMMY, 'Login failed'); } - Cache::put('lemmy_jwt_token', $token, 3600); + // Cache for 50 minutes (3000 seconds) to allow buffer before token expires + Cache::put('lemmy_jwt_token', $token, config('lemmy.token_ttl', 3000)); return $token; } diff --git a/app/Services/Log/LogSaver.php b/app/Services/Log/LogSaver.php deleted file mode 100644 index c1a4e4d..0000000 --- a/app/Services/Log/LogSaver.php +++ /dev/null @@ -1,11 +0,0 @@ - + +
+ {{ $articles->links() }} +
@endsection