Skip to content

Commit

Permalink
Fix redirect for home, make API faster
Browse files Browse the repository at this point in the history
  • Loading branch information
ddxv committed Oct 24, 2023
1 parent 02f5b19 commit d28f51e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
19 changes: 11 additions & 8 deletions backend/api_app/controllers/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ def get_string_date_from_days_ago(days: int) -> str:

def get_app_overview_dict(collection: str) -> Collection:
category_limit = 20
collections = {
"new_weekly": {"title": "New Apps this Week"},
"new_monthly": {"title": "New Apps this Month"},
"new_yearly": {"title": "New Apps this Year"},
"top": {"title": "Alltime Top"},
}

df = query_recent_apps(collection=collection, limit=category_limit)
categories_dicts = []
groups = df.groupby(["mapped_category"])
Expand All @@ -54,7 +49,7 @@ def get_app_overview_dict(collection: str) -> Collection:
)
)
response_collection = Collection(
title=collections[collection]["title"], categories=categories_dicts
title=COLLECTIONS[collection]["title"], categories=categories_dicts
)
return response_collection

Expand All @@ -73,11 +68,11 @@ async def get_apps_overview(self, request: Request, collection: str) -> Collecti
Returns:
A dictionary representation of the list of apps for homepasge
"""
request.logger.info("inside a request")
logger.info(f"{self.path} start")
print(f"collection={collection}")
home_dict = get_app_overview_dict(collection=collection)

logger.info(f"{self.path} return")
return home_dict

@get(path="/{store_id:str}", cache=3600)
Expand All @@ -104,3 +99,11 @@ async def get_app_detail(self, store_id: str) -> AppDetail:
app_dict["history_table"] = app_hist.to_html()

return app_dict


COLLECTIONS = {
"new_weekly": {"title": "New Apps this Week"},
"new_monthly": {"title": "New Apps this Month"},
"new_yearly": {"title": "New Apps this Year"},
"top": {"title": "Alltime Top"},
}
15 changes: 15 additions & 0 deletions backend/dbcon/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ def query_recent_apps(collection: str, limit=20):
ORDER BY rating_count DESC NULLS LAST
);
"""
sel_query = f"""WITH NumberedRows AS (
SELECT
{my_cols},
ROW_NUMBER() OVER (PARTITION BY store, mapped_category
ORDER BY
CASE WHEN store = 1 THEN installs ELSE rating_count END DESC NULLS LAST
) AS rn
FROM {table_name}
)
SELECT
{my_cols}
FROM NumberedRows
WHERE rn <= {limit}
;
"""
df = pd.read_sql(sel_query, con=DBCON.engine)
groups = df.groupby("store")
for _store, group in groups:
Expand Down
14 changes: 12 additions & 2 deletions frontend/src/routes/apps/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,24 @@
<div class="card-header">
<h1 class="h1">{data.myapp.name}</h1>
{#if data.myapp.icon_url_512}
<img src={data.myapp.icon_url_512} alt={data.myapp.name} class="app-icon" />
<img
src={data.myapp.icon_url_512}
alt={data.myapp.name}
class="app-icon"
referrerpolicy="no-referrer"
/>
{/if}
<div>
<Rating total={5} size={50} rating={data.myapp.rating} />
</div>

{#if data.myapp.featured_image}
<img src={data.myapp.featured_image} alt={data.myapp.name} class="app-icon" />
<img
src={data.myapp.featured_image}
alt={data.myapp.name}
class="app-icon"
referrerpolicy="no-referrer"
/>
{/if}
</div>

Expand Down
5 changes: 5 additions & 0 deletions frontend/src/routes/collections/[collection]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
class="h-auto object-fill rounded-lg"
src={app.featured_image_url}
alt={app.name}
referrerpolicy="no-referrer"
/>
</div>
<div class="inline-flex text-left">
<img
class="h-auto w-1/4 p-3 rounded-lg"
src={app.icon_url_512}
alt={app.name}
referrerpolicy="no-referrer"
/>
<AppDetails {app} />
</div>
Expand All @@ -50,18 +52,21 @@
class="h-auto max-w-full rounded-lg"
src={app.phone_image_url_1}
alt={app.name}
referrerpolicy="no-referrer"
/>
<img
class="h-auto w-1/4 rounded-lg"
src={app.icon_url_512}
alt={app.name}
referrerpolicy="no-referrer"
/>
</div>
{:else}
<img
class="h-auto max-w-full rounded-lg"
src={app.icon_url_512}
alt={app.name}
referrerpolicy="no-referrer"
/>
<AppDetails {app} />
{/if}
Expand Down

0 comments on commit d28f51e

Please sign in to comment.