From 439d5330233fbea24c7744c87b4087ee33862962 Mon Sep 17 00:00:00 2001 From: rockstardev <5191402+rockstardev@users.noreply.github.com> Date: Wed, 9 Oct 2024 06:31:18 -0500 Subject: [PATCH] Providing search option by plugin names --- PluginBuilder/Controllers/ApiController.cs | 28 +++++++++++++--------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/PluginBuilder/Controllers/ApiController.cs b/PluginBuilder/Controllers/ApiController.cs index 89b33a0..411d817 100644 --- a/PluginBuilder/Controllers/ApiController.cs +++ b/PluginBuilder/Controllers/ApiController.cs @@ -59,7 +59,7 @@ public IActionResult GetVersion() [HttpGet("plugins")] public async Task Plugins( [ModelBinder(typeof(PluginVersionModelBinder))] PluginVersion? btcpayVersion = null, - bool? includePreRelease = null, bool? includeAllVersions = null) + bool? includePreRelease = null, bool? includeAllVersions = null, string? searchPluginName = null) { includePreRelease ??= false; includeAllVersions ??= false; @@ -69,21 +69,27 @@ public async Task Plugins( false => "get_latest_versions" }; await using var conn = await ConnectionFactory.Open(); - // This query probably doesn't have right indexes + + // This query definitely doesn't have right indexes + var query = $""" + SELECT lv.plugin_slug, lv.ver, p.settings, b.id, b.manifest_info, b.build_info + FROM {getVersions}(@btcpayVersion, @includePreRelease) lv + JOIN builds b ON b.plugin_slug = lv.plugin_slug AND b.id = lv.build_id + JOIN plugins p ON b.plugin_slug = p.slug + WHERE b.manifest_info IS NOT NULL AND b.build_info IS NOT NULL + AND (p.visibility = 'unlisted' OR p.visibility = 'listed') + {(!string.IsNullOrWhiteSpace(searchPluginName) ? "AND (p.slug ILIKE @searchPattern OR b.manifest_info->>'Name' ILIKE @searchPattern)" : "")} + ORDER BY manifest_info->>'Name' + """; var rows = await conn.QueryAsync<(string plugin_slug, int[] ver, string settings, long id, string manifest_info, string build_info)>( - $""" -SELECT lv.plugin_slug, lv.ver, p.settings, b.id, b.manifest_info, b.build_info -FROM {getVersions}(@btcpayVersion, @includePreRelease) lv -JOIN builds b ON b.plugin_slug = lv.plugin_slug AND b.id = lv.build_id -JOIN plugins p ON b.plugin_slug = p.slug -WHERE b.manifest_info IS NOT NULL AND b.build_info IS NOT NULL AND (p.visibility = 'unlisted' OR p.visibility = 'listed') -ORDER BY manifest_info->>'Name' -""", + query, new { btcpayVersion = btcpayVersion?.VersionParts, - includePreRelease = includePreRelease.Value + includePreRelease = includePreRelease.Value, + searchPattern = $"%{searchPluginName}%" }); + rows.TryGetNonEnumeratedCount(out var count); var versions = new List(count); foreach (var r in rows)