From bf39e314d8d8e9b72419a948746ea1a56ae47bca Mon Sep 17 00:00:00 2001 From: Yeuoly Date: Tue, 24 Dec 2024 18:38:12 +0800 Subject: [PATCH] fix: add install count --- api/core/helper/marketplace.py | 6 ++++++ api/services/plugin/plugin_service.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/api/core/helper/marketplace.py b/api/core/helper/marketplace.py index 743bef9316..f4129b88ed 100644 --- a/api/core/helper/marketplace.py +++ b/api/core/helper/marketplace.py @@ -27,3 +27,9 @@ def batch_fetch_plugin_manifests(plugin_ids: list[str]) -> Sequence[MarketplaceP response = requests.post(url, json={"plugin_ids": plugin_ids}) response.raise_for_status() return [MarketplacePluginDeclaration(**plugin) for plugin in response.json()["data"]["plugins"]] + + +def record_install_plugin_event(plugin_unique_identifier: str): + url = str(URL(str(dify_config.MARKETPLACE_API_URL)) / "api/v1/stats/plugins/install_count") + response = requests.post(url, json={"unique_identifier": plugin_unique_identifier}) + response.raise_for_status() diff --git a/api/services/plugin/plugin_service.py b/api/services/plugin/plugin_service.py index 701b7c6171..e3c37ecba7 100644 --- a/api/services/plugin/plugin_service.py +++ b/api/services/plugin/plugin_service.py @@ -144,7 +144,8 @@ class PluginService: try: manager.fetch_plugin_manifest(tenant_id, new_plugin_unique_identifier) - # already downloaded, skip + # already downloaded, skip, and record install event + marketplace.record_install_plugin_event(new_plugin_unique_identifier) except Exception: # plugin not installed, download and upload pkg pkg = download_plugin_pkg(new_plugin_unique_identifier)