mirror of
https://github.com/sp-tarkov/forge.git
synced 2025-02-13 04:30:41 -05:00
Refringe
1783a683ed
- Updated the SptVersion and ModVersion dependancies to resolve *all* compatible versions and introduced new relationships to pull just the latest compatible version. Had to rewrite a *bunch*, but it should be much more capable now. It can be expensive to resolve these properties when iterated over, so *make sure they're eager loaded using the `with` method when you're building the queries*. - Updated the mod listing Livewire component to save the filter options within the PHP session instead of in browser local storage. *Much* cleaner. - Removed caching from homepage queries to see how they preform on production. Will add back later. - Updated ModVersion factory to create SptVersions if there are none specified. - Probably lots of other changes too... I need to make smaller commits. :(
39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\ModVersion;
|
|
use App\Models\SptVersion;
|
|
use Composer\Semver\Semver;
|
|
|
|
class SptVersionService
|
|
{
|
|
/**
|
|
* Resolve dependencies for the given mod version.
|
|
*/
|
|
public function resolve(ModVersion $modVersion): void
|
|
{
|
|
$satisfyingVersionIds = $this->satisfyConstraint($modVersion);
|
|
$modVersion->sptVersions()->sync($satisfyingVersionIds);
|
|
}
|
|
|
|
/**
|
|
* Satisfies the version constraint of a given ModVersion. Returns the ID of the satisfying SptVersion.
|
|
*/
|
|
private function satisfyConstraint(ModVersion $modVersion): array
|
|
{
|
|
$availableVersions = SptVersion::query()
|
|
->orderBy('version', 'desc')
|
|
->pluck('id', 'version')
|
|
->toArray();
|
|
|
|
$satisfyingVersions = Semver::satisfiedBy(array_keys($availableVersions), $modVersion->spt_version_constraint);
|
|
if (empty($satisfyingVersions)) {
|
|
return [];
|
|
}
|
|
|
|
// Return the IDs of all satisfying versions
|
|
return array_map(fn ($version) => $availableVersions[$version], $satisfyingVersions);
|
|
}
|
|
}
|