From 08747941409e44424796f2983c29e2f6b4c3237c Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 1 Nov 2024 21:09:53 +0300 Subject: [PATCH] stat-dict --- resolvers/reader.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/resolvers/reader.py b/resolvers/reader.py index daffd764..b3ea6c0d 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -220,12 +220,13 @@ def get_shouts_with_links(info, q, limit=20, offset=0): "slug": a.slug, "pic": a.pic, } - # logger.info({ **shout_dict, "body": "", "media": []}) - stat = json.loads(row.stat) if hasattr(row, "stat") else {} - viewed = ViewedStorage.get_shout(shout_id=shout_id) or 0 - stat["viewed"] = viewed - if stat: - shout_dict["stat"] = {**stat, "commented": stat.get("comments_count", 0)} + if hasattr(row, "stat") and isinstance(row.stat, dict): + viewed = ViewedStorage.get_shout(shout_id=shout_id) or 0 + shout_dict["stat"] = { + **row.stat, + "viewed": viewed, + "commented": row.stat.get("comments_count", 0) + } if has_field(info, "main_topic") and hasattr(row, "main_topic"): shout_dict["main_topic"] = json.loads(row.main_topic)