Refactor, clean up
This commit is contained in:
parent
2409c818ee
commit
57d91f8790
8 changed files with 19 additions and 30 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 [];
|
||||
}
|
||||
}
|
||||
|
|
@ -54,11 +56,9 @@ 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]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Log;
|
||||
|
||||
class LogSaver
|
||||
{
|
||||
public function log()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -21,4 +21,8 @@
|
|||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="pagination-wrapper">
|
||||
{{ $articles->links() }}
|
||||
</div>
|
||||
@endsection
|
||||
|
|
|
|||
Loading…
Reference in a new issue