-
Notifications
You must be signed in to change notification settings - Fork 3
Add reuse_prototype field to /wiki API endpoint
#1082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
outdooracorn
wants to merge
14
commits into
main
Choose a base branch
from
ollie/reuse-prototype
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c43c6a4
PoC: Add `reuse_prototype` field to `/wiki` API endpoint
outdooracorn 73a92e7
add test for reuse_prototype
dati18 07bb19b
Add load-state-aware reuse_prototype resource logic
dati18 9233389
Remove temporary reuse_prototype debug fields
dati18 69da736
Replace TODO with a purpose-focus explaintion for the local listener
dati18 a06042e
Add /reusePrototype endpoint
dati18 e7a36ef
Eager-load Wiki model and preloads WikiLatestProfile in show()
dati18 84f1b51
Add PublicWikiControllerTest unit test for loaded relation
dati18 a5e0f75
Change endpoint to reusePrototype to explicitly verify that route
dati18 5c931e2
extend testReusePrototype to also call GET /reusePrototype/{id}
dati18 bdd52e8
Check the model has the relation loaded
dati18 0657731
add unit test and query count for index()
dati18 a993cba
remove debugging "echo"
dati18 e48435f
Apply suggestions from reviews
dati18 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| <?php | ||
|
|
||
| namespace Tests\Http\Controllers; | ||
|
|
||
| use App\Http\Controllers\PublicWikiController; | ||
| use App\Http\Resources\PublicWikiResource; | ||
| use App\Wiki; | ||
| use App\WikiProfile; | ||
| use Illuminate\Database\Events\QueryExecuted; | ||
| use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
| use Illuminate\Http\Request; | ||
| use Illuminate\Support\Facades\DB; | ||
| use Tests\TestCase; | ||
|
|
||
| class PublicWikiControllerTest extends TestCase { | ||
| use DatabaseTransactions; | ||
|
|
||
| public function testShowLoadsWikiLatestProfileForResource(): void { | ||
| $wiki = Wiki::factory()->create([ | ||
| 'domain' => 'controller-test.wikibase.cloud', | ||
| 'sitename' => 'controller-test', | ||
| ]); | ||
|
|
||
| WikiProfile::create([ | ||
| 'wiki_id' => $wiki->id, | ||
| 'purpose' => 'data_hub', | ||
| 'temporality' => 'permanent', | ||
| 'audience' => 'wide', | ||
| ]); | ||
|
|
||
| $controller = new PublicWikiController; | ||
| $resource = $controller->show($wiki->id); | ||
|
|
||
| $this->assertInstanceOf(PublicWikiResource::class, $resource); | ||
| $this->assertSame(true, $resource->toArray(new Request)['reuse_prototype']); | ||
| } | ||
|
|
||
| public function testIndexEagerLoadsWikiLatestProfileOnceForCollection(): void { | ||
| for ($i = 1; $i <= 3; $i++) { | ||
| $wiki = Wiki::factory()->create([ | ||
| 'domain' => "index-eager-load-test-{$i}.wikibase.cloud", | ||
| 'sitename' => "Index Eager Load Test Site {$i}", | ||
| ]); | ||
|
|
||
| WikiProfile::create([ | ||
| 'wiki_id' => $wiki->id, | ||
| 'purpose' => 'data_hub', | ||
| 'temporality' => 'permanent', | ||
| 'audience' => 'wide', | ||
| ]); | ||
| } | ||
|
|
||
| $profileQueryCount = 0; | ||
| DB::listen(function (QueryExecuted $query) use (&$profileQueryCount): void { | ||
| if (str_contains($query->sql, 'wiki_profiles')) { | ||
| $profileQueryCount++; | ||
| } | ||
| }); | ||
|
|
||
| $controller = new PublicWikiController; | ||
| $resourceCollection = $controller->index(new Request); | ||
|
|
||
| $this->assertSame(1, $profileQueryCount); | ||
| $this->assertTrue($resourceCollection->first()->relationLoaded('wikiLatestProfile')); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stream or file "/var/www/html/storage/logs/laravel-2026-05-29.log" could not be opened in append mode: Failed to open stream: Permission deniedI got the above error again and tracked it down to:
/var/www/html/storage/logs/were owned byroot:rootrather thanwww-data:www-dataI don't think it's an issue in staging/production as I don't think logging to a file is enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I just checked and had the same issue. But you've already specified "local"-only so I don't think it's going to be a problem on staging/prod