Skip to content

Commit d6699cb

Browse files
committed
Fix: Smaller bugs
1 parent 6a1b157 commit d6699cb

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

backend/app/models/history.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,36 @@ def find_all(cls) -> list[Self]:
8181

8282
@classmethod
8383
def get_recent(cls, shoppinglist_id: int, limit: int = 9) -> list[Self]:
84-
sq = db.session.query(ShoppinglistItems.item_id).subquery().select()
85-
sq2 = (
86-
cls.query.filter(
87-
cls.shoppinglist_id == shoppinglist_id,
88-
cls.status == Status.DROPPED,
89-
cls.item_id.notin_(sq),
84+
if "postgresql" in db.engine.name:
85+
sq = db.session.query(ShoppinglistItems.item_id).subquery().select()
86+
sq2 = (
87+
cls.query.filter(
88+
cls.shoppinglist_id == shoppinglist_id,
89+
cls.status == Status.DROPPED,
90+
cls.item_id.notin_(sq),
91+
)
92+
.distinct(cls.item_id)
93+
.order_by(cls.item_id, cls.created_at.desc())
94+
.limit(limit)
95+
.subquery()
96+
)
97+
alias = db.aliased(cls, sq2)
98+
q = db.session.query(alias).order_by(alias.created_at.desc())
99+
return q.all()
100+
else:
101+
sq = db.session.query(ShoppinglistItems.item_id).subquery().select()
102+
sq2 = (
103+
db.session.query(func.max(cls.id))
104+
.filter(cls.status == Status.DROPPED)
105+
.filter(cls.item_id.notin_(sq))
106+
.group_by(cls.item_id)
107+
.join(cls.item)
108+
.subquery()
109+
.select()
110+
)
111+
return (
112+
cls.query.filter(cls.shoppinglist_id == shoppinglist_id)
113+
.filter(cls.id.in_(sq2))
114+
.order_by(cls.created_at.desc(), cls.item_id)
115+
.limit(limit)
90116
)
91-
.distinct(cls.item_id)
92-
.order_by(cls.item_id, cls.created_at.desc())
93-
.limit(limit)
94-
.subquery()
95-
)
96-
alias = db.aliased(cls, sq2)
97-
q = db.session.query(alias).order_by(alias.created_at.desc())
98-
return q.all()

backend/app/service/recipe_scraping.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
def scrapePublic(url: str, html: str, household: Household) -> dict | None:
1414
try:
15-
scraper = scrape_html(html, url, supported_only=False, wild_mode=True)
15+
scraper = scrape_html(html, url, supported_only=False)
1616
except:
1717
return None
1818
recipe = Recipe()
@@ -133,9 +133,7 @@ def scrapeKitchenOwl(original_url: str, api_url: str, recipe_id: int) -> dict |
133133
items = {}
134134

135135
for ingredient in recipe["items"]:
136-
items[ingredient["name"] + " " + ingredient["description"]] = (
137-
ingredient.obj_to_item_dict()
138-
)
136+
items[ingredient["name"] + " " + ingredient["description"]] = ingredient
139137

140138
return {"recipe": recipe, "items": items}
141139

@@ -162,7 +160,11 @@ def scrape(url: str, household: Household) -> dict | None:
162160
if res.status_code != requests.codes.ok:
163161
return None
164162

165-
if kitchenowlMatch and hashlib.sha256(res.text.encode()).hexdigest() == "3fc2629051e92fa54c26cf5e44efac1014eb89a2eb46dd644dae4f3db5cd3eaa":
163+
if (
164+
kitchenowlMatch
165+
and hashlib.sha256(res.text.encode()).hexdigest()
166+
== "87d851b8a5949da174eb8f43579438242ae2119f0a6cac0718884c52f2a77124"
167+
):
166168
return scrapeKitchenOwl(
167169
url, kitchenowlMatch.group(1) + "/api", int(kitchenowlMatch.group(2))
168170
)

kitchenowl/lib/models/recipe.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Recipe extends Model implements ISuspensionBean {
7373
source: map['source'] ?? '',
7474
image: map['photo'],
7575
imageHash: map['photo_hash'],
76-
public: map['public'],
76+
public: map['public'] ?? false,
7777
householdId: map['household_id'],
7878
items: items,
7979
tags: tags,

0 commit comments

Comments
 (0)