Skip to content

Commit

Permalink
Merge pull request #89 from frontChapter/develop
Browse files Browse the repository at this point in the history
add image
  • Loading branch information
lokiwich authored Feb 29, 2024
2 parents ea14464 + d1772d2 commit ef2890a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule): void
{
$schedule->job(new ProcessFestivalSitesScore())->everyTenMinutes();
$schedule->job(new ProcessFestivalSitesScore())->everyMinute();
$schedule->job(new UnblockSpammers())->everyMinute();
$schedule->command('disposable:update')->daily();
}
Expand Down
3 changes: 2 additions & 1 deletion app/Jobs/ProcessFestivalSitesScore.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ public function handle(): void
foreach($festivalSites as $festivalSite) {
$vote = Votable::where('votable_type', FestivalSite::class)
->where('votable_id', $festivalSite->id)
->selectRaw('votable_id, (sum(vote) / count(vote)) as score')
->selectRaw('votable_id, (sum(vote) / count(vote)) as score, sum(vote) as count')
->groupBy('votable_id')
->first();

if (!empty($vote)) {
$festivalSite->score = $vote->score;
$festivalSite->count = $vote->count;
$festivalSite->save();
}
}
Expand Down
1 change: 1 addition & 0 deletions app/Livewire/Festival/ListSites.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ListSites extends Component
public function getSites()
{
return FestivalSite::whereStatus(FestivalSiteStatus::PUBLISHED)
->orderBy("count", "DESC")
->orderBy("score", "DESC")
->paginate(23);
}
Expand Down
1 change: 1 addition & 0 deletions app/Models/FestivalSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class FestivalSite extends Model implements Viewable
'user_id',
'app_id',
'name',
'count',
'url',
'logo',
'status',
Expand Down
28 changes: 28 additions & 0 deletions database/migrations/2024_02_29_161756_add_count_to_sites.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('festival_sites', function (Blueprint $table) {
$table->integer('count')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('festival_sites', function (Blueprint $table) {
$table->dropColumn('count');
});
}
};

0 comments on commit ef2890a

Please sign in to comment.