Refactor, clean up

This commit is contained in:
myrmidex 2025-07-03 21:34:39 +02:00
parent 2409c818ee
commit 57d91f8790
8 changed files with 19 additions and 30 deletions

View file

@ -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

View file

@ -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'));
}

View file

@ -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();
}
}

View file

@ -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));
});
}

View file

@ -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]);
}
}

View file

@ -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;
}

View file

@ -1,11 +0,0 @@
<?php
namespace App\Services\Log;
class LogSaver
{
public function log()
{
}
}

View file

@ -21,4 +21,8 @@
@endforeach
</tbody>
</table>
<div class="pagination-wrapper">
{{ $articles->links() }}
</div>
@endsection