Skip to content

Commit

Permalink
Merge pull request #34 from btcpayserver/feat/search-plugin-name
Browse files Browse the repository at this point in the history
Providing search option by plugin names
  • Loading branch information
rockstardev authored Oct 10, 2024
2 parents dcef58d + 439d533 commit b83c9a5
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions PluginBuilder/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public IActionResult GetVersion()
[HttpGet("plugins")]
public async Task<IActionResult> 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;
Expand All @@ -69,21 +69,27 @@ public async Task<IActionResult> 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<PublishedVersion>(count);
foreach (var r in rows)
Expand Down

0 comments on commit b83c9a5

Please sign in to comment.