From 10832bb6d18c9de0e4450cf1c962ec38eabaa0e2 Mon Sep 17 00:00:00 2001 From: Shanee Date: Tue, 7 Jan 2025 23:46:52 -0500 Subject: [PATCH 1/3] fix(mongodb): changed save and count to insert_one and count_documents --- scripts/scheduled/metrics.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/scheduled/metrics.py b/scripts/scheduled/metrics.py index 8b2171243e..46f74a3bac 100644 --- a/scripts/scheduled/metrics.py +++ b/scripts/scheduled/metrics.py @@ -21,10 +21,10 @@ contributors = len(contributors) # Number of Links -links = db.links.count() +links = db.links.count_documents() # Number of Source sheets -sheets = db.sheets.count() +sheets = db.sheets.count_documents() metrics = { "timestamp": datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0), @@ -37,6 +37,6 @@ } try: - db.metrics.save(metrics) + db.metrics.insert_one(metrics) except DuplicateKeyError: pass From e15352b54d1dd495307c13df0b7fcbd52ae94e48 Mon Sep 17 00:00:00 2001 From: Shanee Date: Tue, 7 Jan 2025 23:50:07 -0500 Subject: [PATCH 2/3] fix(abstracttextrecord): word_count function was failing not gracefully on index without nodes --- sefaria/model/text.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sefaria/model/text.py b/sefaria/model/text.py index 6e088c9589..1a0b5f2c32 100644 --- a/sefaria/model/text.py +++ b/sefaria/model/text.py @@ -1029,7 +1029,11 @@ class AbstractTextRecord(object): def word_count(self): """ Returns the number of words in this text """ - return self.ja(remove_html=True).word_count() + try: + wc = self.ja(remove_html=True).word_count() + except AttributeError: + wc = 0 + return wc def char_count(self): """ Returns the number of characters in this text """ From 9257c6f09b217cb32b12948c4f4a3ab76f10fb92 Mon Sep 17 00:00:00 2001 From: Shanee Date: Wed, 8 Jan 2025 00:25:37 -0500 Subject: [PATCH 3/3] fix(mongodbapi): count_documents needs a query --- scripts/scheduled/metrics.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/scheduled/metrics.py b/scripts/scheduled/metrics.py index 46f74a3bac..1e61330fed 100644 --- a/scripts/scheduled/metrics.py +++ b/scripts/scheduled/metrics.py @@ -21,10 +21,10 @@ contributors = len(contributors) # Number of Links -links = db.links.count_documents() +links = db.links.count_documents({}) # Number of Source sheets -sheets = db.sheets.count_documents() +sheets = db.sheets.count_documents({}) metrics = { "timestamp": datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0),