Skip to content

Commit fe4dc1f

Browse files
committed
Allow to set no_cache options via info provider UI
1 parent 4137bde commit fe4dc1f

6 files changed

Lines changed: 60 additions & 9 deletions

File tree

src/Controller/InfoProviderController.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use App\Services\InfoProviderSystem\PartInfoRetriever;
3232
use App\Services\InfoProviderSystem\ProviderRegistry;
3333
use App\Services\InfoProviderSystem\Providers\GenericWebProvider;
34+
use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
3435
use App\Settings\AppSettings;
3536
use App\Settings\InfoProviderSystem\InfoProviderGeneralSettings;
3637
use Doctrine\ORM\EntityManagerInterface;
@@ -172,10 +173,15 @@ public function search(Request $request, #[MapEntity(id: 'target')] ?Part $updat
172173
$keyword = $form->get('keyword')->getData();
173174
$providers = $form->get('providers')->getData();
174175

176+
$no_cache_search = $form->get('no_cache_search')->getData();
177+
$no_cache_details = $form->get('no_cache_details')->getData();
178+
175179
$dtos = [];
176180

177181
try {
178-
$dtos = $this->infoRetriever->searchByKeyword(keyword: $keyword, providers: $providers);
182+
$dtos = $this->infoRetriever->searchByKeyword(keyword: $keyword, providers: $providers, options: [
183+
InfoProviderInterface::OPTION_NO_CACHE => $no_cache_search
184+
]);
179185
} catch (ClientException $e) {
180186
$this->addFlash('error', t('info_providers.search.error.client_exception'));
181187
$this->addFlash('error',$e->getMessage());
@@ -207,7 +213,8 @@ public function search(Request $request, #[MapEntity(id: 'target')] ?Part $updat
207213
return $this->render('info_providers/search/part_search.html.twig', [
208214
'form' => $form,
209215
'results' => $results,
210-
'update_target' => $update_target
216+
'update_target' => $update_target,
217+
'no_cache_details' => $no_cache_details ?? false,
211218
]);
212219
}
213220

src/Controller/PartController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,13 @@ public function updateFromInfoProvider(
346346
$this->denyAccessUnlessGranted('edit', $part);
347347
$this->denyAccessUnlessGranted('@info_providers.create_parts');
348348

349+
//Force info providers to not use cache, when retrieving part details for creating a new part, because otherwise we might end up with outdated information
350+
$no_cache = $request->query->getBoolean('no_cache', false);
351+
349352
//Save the old name of the target part for the template
350353
$old_name = $part->getName();
351354

352-
$dto = $infoRetriever->getDetails($providerKey, $providerId);
355+
$dto = $infoRetriever->getDetails($providerKey, $providerId, [InfoProviderInterface::OPTION_NO_CACHE => $no_cache]);
353356
$provider_part = $infoRetriever->dtoToPart($dto);
354357

355358
$part = $partMerger->merge($part, $provider_part);

src/Form/InfoProviderSystem/PartSearchType.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
namespace App\Form\InfoProviderSystem;
2525

2626
use Symfony\Component\Form\AbstractType;
27+
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
2728
use Symfony\Component\Form\Extension\Core\Type\SearchType;
2829
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
2930
use Symfony\Component\Form\FormBuilderInterface;
@@ -40,8 +41,17 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
4041
'help' => 'info_providers.search.providers.help',
4142
]);
4243

44+
$builder->add('no_cache_search', CheckboxType::class, [
45+
'label' => 'info_providers.no_cache_search',
46+
'required' => false,
47+
]);
48+
$builder->add('no_cache_details', CheckboxType::class, [
49+
'label' => 'info_providers.no_cache_details',
50+
'required' => false,
51+
]);
52+
4353
$builder->add('submit', SubmitType::class, [
4454
'label' => 'info_providers.search.submit'
4555
]);
4656
}
47-
}
57+
}

src/Services/InfoProviderSystem/PartInfoRetriever.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function searchByKeyword(string $keyword, array $providers, array $option
8080
}
8181

8282
/** @noinspection SlowArrayOperationsInLoopInspection */
83-
$results = array_merge($results, $this->searchInProvider($provider, $keyword));
83+
$results = array_merge($results, $this->searchInProvider($provider, $keyword, $options));
8484
}
8585

8686
return $results;

templates/info_providers/search/part_search.html.twig

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@
3333
</div>
3434
</div>
3535

36+
<div class="row mb-2">
37+
<div class="{{ col_input }} {{ offset_label }}">
38+
<a data-bs-toggle="collapse" href="#infoSearchAdvancedPanel">{% trans %}info_providers.search.advanced_options{% endtrans %}</a>
39+
</div>
40+
</div>
41+
42+
<div class="collapse" id="infoSearchAdvancedPanel">
43+
<div class="card card-body mb-2">
44+
{{ form_row(form.no_cache_search) }}
45+
{{ form_row(form.no_cache_details) }}
46+
</div>
47+
</div>
48+
3649
{{ form_row(form.submit) }}
3750

3851
{{ form_end(form) }}
@@ -116,16 +129,16 @@
116129

117130
{% if update_target %} {# We update an existing part #}
118131
{% set href = path('info_providers_update_part',
119-
{'providerKey': dto.provider_key, 'providerId': dto.provider_id, 'id': update_target.iD}) %}
132+
{'providerKey': dto.provider_key, 'providerId': dto.provider_id, 'id': update_target.iD, 'no_cache': no_cache_details ? 1 : null}) %}
120133
{% else %} {# Create a fresh part #}
121134
{% set href = path('info_providers_create_part',
122-
{'providerKey': dto.provider_key, 'providerId': dto.provider_id}) %}
135+
{'providerKey': dto.provider_key, 'providerId': dto.provider_id, 'no_cache': no_cache_details ? 1 : null}) %}
123136
{% endif %}
124137

125138
{# If we have no local part, then we can just show the create button #}
126139
{% if localPart is null %}
127140
<a class="btn btn-primary" href="{{ href }}"
128-
target="_blank" title="{% trans %}part.create.btn{% endtrans %}">
141+
target="_blank" title="{% trans %}part.create.btn{% endtrans %}">
129142
<i class="fa-solid fa-plus-square"></i>
130143
</a>
131144
{% else %} {# Otherwise add a button group with all three buttons #}
@@ -139,7 +152,7 @@
139152
target="_blank" title="{% trans %}info_providers.search.show_existing_part{% endtrans %}">
140153
<i class="fa-solid fa-search"></i>
141154
</a>
142-
<a class="btn btn-primary" href="{{ path("info_providers_update_part", {'id': localPart.id, 'providerKey': dto.provider_key, 'providerId': dto.provider_id}) }}"
155+
<a class="btn btn-primary" href="{{ path("info_providers_update_part", {'id': localPart.id, 'providerKey': dto.provider_key, 'providerId': dto.provider_id, 'no_cache': no_cache_details ? 1 : null }) }}"
143156
target="_blank" title="{% trans %}info_providers.search.update_existing_part{% endtrans %}">
144157
<i class="fa-solid fa-arrows-rotate"></i>
145158
</a>

translations/messages.en.xlf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13139,5 +13139,23 @@ Buerklin-API Authentication server:
1313913139
<target>The additional instructions will be appended to the system prompt.</target>
1314013140
</segment>
1314113141
</unit>
13142+
<unit id="Ycfssj2" name="info_providers.search.advanced_options">
13143+
<segment>
13144+
<source>info_providers.search.advanced_options</source>
13145+
<target>Advanced options</target>
13146+
</segment>
13147+
</unit>
13148+
<unit id="xfxZrXn" name="info_providers.no_cache_search">
13149+
<segment>
13150+
<source>info_providers.no_cache_search</source>
13151+
<target>Do not cache search results / Force fresh search</target>
13152+
</segment>
13153+
</unit>
13154+
<unit id="b_oc3T1" name="info_providers.no_cache_details">
13155+
<segment>
13156+
<source>info_providers.no_cache_details</source>
13157+
<target>Do not cache result details / Force fresh part detail retrieval</target>
13158+
</segment>
13159+
</unit>
1314213160
</file>
1314313161
</xliff>

0 commit comments

Comments
 (0)