Skip to content

Commit

Permalink
perf: offloading file download when using S3 services
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile committed May 15, 2024
1 parent 8f2c8b8 commit 603aa24
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 7 additions & 1 deletion app/Http/Controllers/RepositoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public function __invoke(Request $request, string $type, Repository $repository,
abort(404);
}

return Storage::download($fileToDownload);
// When using the local driver, we can just return the file
if (! Storage::providesTemporaryUrls()) {
return Storage::download($fileToDownload);
}

// This offloads the download directly to the client
return redirect(Storage::temporaryUrl($fileToDownload, now()->addMinute()));
}
}
9 changes: 3 additions & 6 deletions tests/Feature/RepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
return ['enterprise', 'community'];
});

beforeEach(function () {
Storage::fake();
});

it('returns not found if wrong repo')
->get('repository/hello_world/nethsecurity/packages/x86_64/base/Packages')
->assertNotFound();
Expand Down Expand Up @@ -87,18 +83,19 @@
})->with('repositories');

it('downloads file', function ($repository) {
Storage::fake();
// this tests the cache process
$uuid = fake()->uuid();
Cache::shouldReceive('has')
->with($uuid)
->andReturnTrue();

$repo = Repository::factory()->create();
$stablePath = $repo->getStablePath().now()->toAtomString();
$stablePath = $repo->snapshotDir().'/'.now()->toAtomString();
Storage::createDirectory($stablePath);
$file = UploadedFile::fake()->create('Packages');
Storage::putFileAs($stablePath.'/packages/x86_64/base', $file, 'Packages');
withBasicAuth($uuid, '')
->get("/repository/$repository/$repo->name/packages/x86_64/base/Packages")
->assertSuccessful();
->assertRedirect();
})->with('repositories');

0 comments on commit 603aa24

Please sign in to comment.