Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Http/Controllers/PublicWikiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function index(Request $request) {
]);

$params = array_merge(self::$defaultParams, $request->input());
$query = Wiki::query();
$query = Wiki::query()->with('wikiLatestProfile');

if (array_key_exists('is_featured', $params)) {
$query = $query->where([
Expand Down
10 changes: 10 additions & 0 deletions app/Http/Resources/PublicWikiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ public function toArray($request): array {
'sitename' => $this->sitename,
'wiki_site_stats' => $this->wikiSiteStats,
'logo_url' => $logoSetting ? $logoSetting->value : null,

// Checking relation load state before reading it to avoid N+1 query
// This relies on the controller to eager load `wikiLatestProfile` relationship
'reuse_prototype' => $this->relationLoaded('wikiLatestProfile')
? ($this->wikiLatestProfile
? $this->wikiLatestProfile->purpose === 'data_hub'
&& $this->wikiLatestProfile->temporality === 'permanent'
&& $this->wikiLatestProfile->audience === 'wide'
: null)
: null,
];
}
}
12 changes: 12 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Http\Curl\CurlRequest;
use App\Http\Curl\HttpRequest;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Queue\Events\JobFailed;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\ServiceProvider;
Expand All @@ -25,5 +26,16 @@ public function boot(): void {
$wrappedException = new \Exception("Executing Job '$name' failed.", 1, $event->exception);
report($wrappedException);
});

// TODO: delete this listener before merging or is it useful to keep in the local environment?
Copy link
Copy Markdown
Contributor

@dati18 dati18 May 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's useful and want to keep it here

if ($this->app->environment('local')) {
\Event::listen(QueryExecuted::class, function (QueryExecuted $query) {
\Log::debug('Query Executed: ', [
'sql' => $query->sql,
'bindings' => $query->bindings,
'connection' => $query->connectionName,
]);
});
}
}
}
47 changes: 47 additions & 0 deletions tests/Routes/Wiki/PublicWikiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Routes\Wiki;

use App\Wiki;
use App\WikiProfile;
use App\WikiSetting;
use App\WikiSiteStats;
use Illuminate\Foundation\Testing\DatabaseTransactions;
Expand All @@ -18,12 +19,14 @@ class PublicWikiTest extends TestCase {
protected function setUp(): void {
parent::setUp();
Wiki::query()->delete();
WikiProfile::query()->delete();
WikiSiteStats::query()->delete();
WikiSetting::query()->delete();
}

protected function tearDown(): void {
Wiki::query()->delete();
WikiProfile::query()->delete();
WikiSiteStats::query()->delete();
WikiSetting::query()->delete();
parent::tearDown();
Expand Down Expand Up @@ -279,4 +282,48 @@ public function testLogoUrl() {
)
->assertJsonPath('data.1.logo_url', null);
}

public function testReusePrototype() {
$reusableWiki = Wiki::factory()->create([
'domain' => 'reusable.wikibase.cloud', 'sitename' => 'asite',
]);
WikiSiteStats::factory()->create([
'wiki_id' => $reusableWiki->id,
]);
WikiProfile::create([
'wiki_id' => $reusableWiki->id,
'purpose' => 'data_hub',
'temporality' => 'permanent',
'audience' => 'wide',
]);

$nonReusableWiki = Wiki::factory()->create([
'domain' => 'non-reusable.wikibase.cloud', 'sitename' => 'bsite',
]);
WikiSiteStats::factory()->create([
'wiki_id' => $nonReusableWiki->id,
]);
WikiProfile::create([
'wiki_id' => $nonReusableWiki->id,
'purpose' => 'other',
'temporality' => 'other',
'audience' => 'other',
]);

$noProfileWiki = Wiki::factory()->create([
'domain' => 'no-profile.wikibase.cloud', 'sitename' => 'csite',
]);
WikiSiteStats::factory()->create([
'wiki_id' => $noProfileWiki->id,
]);

$this->json('GET', $this->route)
->assertStatus(200)
->assertJsonPath('data.0.domain', 'reusable.wikibase.cloud')
->assertJsonPath('data.0.reuse_prototype', true)
->assertJsonPath('data.1.domain', 'non-reusable.wikibase.cloud')
->assertJsonPath('data.1.reuse_prototype', false)
->assertJsonPath('data.2.domain', 'no-profile.wikibase.cloud')
->assertJsonPath('data.2.reuse_prototype', null);
}
}
Loading