Skip to content
This repository has been archived by the owner on Apr 25, 2022. It is now read-only.

Ingest addons and allow to query them #86

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def load_appstream():
p.sadd("types:index", type)
p.sadd(f"types:{type}", redis_key)

if extends := apps[appid].get("extends"):
p.sadd(f"addons:{extends}", redis_key)

if categories := apps[appid].get("categories"):
for category in categories:
p.sadd("categories:index", category)
Expand All @@ -62,6 +65,7 @@ def load_appstream():
f"fts:{appid}",
f"summary:{appid}",
f"app_stats:{appid}",
f"addons:{appid}",
)
db.redis_search.delete_document(f"fts:{appid}")

Expand Down Expand Up @@ -103,6 +107,16 @@ def get_developer(developer: str):
return []


def get_addons(appid: str):
if index := db.redis_conn.smembers(f"addons:{appid}"):
json_appdata = db.redis_conn.mget(index)
appdata = [json.loads(app) for app in json_appdata]

return [(app["id"]) for app in appdata]
else:
return []


def search(query: str):
if results := db.search(query):
appids = tuple(doc_id.replace("fts", "apps") for doc_id in results)
Expand Down
16 changes: 16 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections import defaultdict
from functools import lru_cache

import sentry_sdk
Expand Down Expand Up @@ -122,6 +123,21 @@ def get_developer(
return sorted_ids


@app.get("/addon/{appid}")
def get_addons(appid: str):
ids = apps.get_addons(appid)

addon_appstreams = defaultdict()
for addonid in ids:
addon_appstreams[addonid] = db.get_json_key(f"apps:{addonid}")
sorted_ids = sorted(
ids,
key=lambda appid: addon_appstreams[appid].get("name", "Unknown"),
)

return sorted_ids


@app.get("/appstream")
def list_appstream(type: schemas.Type = schemas.Type.Desktop):
return apps.list_appstream(type)
Expand Down