Skip to content

armgit / mwmbl

Public Imported from GitHub
0

An open source, non-profit web search engine

Reinstate some stats

Daoud Clarke47df19b840bf
diff --git a/mwmbl/crawler/app.py b/mwmbl/crawler/app.py
index fbb6258..55ea1d5 100644
--- a/mwmbl/crawler/app.py
+++ b/mwmbl/crawler/app.py
@@ -94,7 +94,7 @@ def create_router(batch_cache: BatchCache, queued_batches: RedisURLQueue, versio
epoch_time = (now - datetime(1970, 1, 1, tzinfo=timezone.utc)).total_seconds()
hashed_batch = HashedBatch(user_id_hash=user_id_hash, timestamp=epoch_time, items=batch.items)
- # stats_manager.record_batch(hashed_batch)
+ stats_manager.record_batch(hashed_batch)
data = gzip.compress(hashed_batch.json().encode('utf8'))
upload(data, filename)
diff --git a/mwmbl/crawler/stats.py b/mwmbl/crawler/stats.py
index ac35906..d02c943 100644
--- a/mwmbl/crawler/stats.py
+++ b/mwmbl/crawler/stats.py
@@ -97,35 +97,36 @@ class StatsManager:
self.redis.zincrby(user_count_key, num_crawled_urls, hashed_batch.user_id_hash)
self.redis.expire(user_count_key, SHORT_EXPIRE_SECONDS)
- host_key = HOST_COUNT_KEY.format(date=date)
- host_all_key = HOST_COUNT_ALL_KEY.format(date=date)
- with URLDatabase() as url_db:
- for item in hashed_batch.items:
- host = urlparse(item.url).netloc
- self.redis.zincrby(host_all_key, 1, host)
-
- if item.content is None:
- continue
-
- self.redis.zincrby(host_key, 1, host)
-
- links = []
- if item.content.links is not None:
- links += item.content.links
- if item.content.extra_links is not None:
- links += item.content.extra_links
- if item.content.link_details is not None:
- links += [link.url for link in item.content.link_details]
-
- for link in links:
- link_host = urlparse(link).netloc
- self.redis.zincrby(HOST_COUNT_LINK_KEY.format(date=date), 1, link_host)
-
- if link not in url_db:
- self.redis.zincrby(HOST_COUNT_LINK_NEW_KEY.format(date=date), 1, link_host)
-
- self.redis.expire(host_key, SHORT_EXPIRE_SECONDS)
- self.redis.expire(host_all_key, SHORT_EXPIRE_SECONDS)
+ # Currently commented out for performance reasons
+ # host_key = HOST_COUNT_KEY.format(date=date)
+ # host_all_key = HOST_COUNT_ALL_KEY.format(date=date)
+ # with URLDatabase() as url_db:
+ # for item in hashed_batch.items:
+ # host = urlparse(item.url).netloc
+ # self.redis.zincrby(host_all_key, 1, host)
+ #
+ # if item.content is None:
+ # continue
+ #
+ # self.redis.zincrby(host_key, 1, host)
+ #
+ # links = []
+ # if item.content.links is not None:
+ # links += item.content.links
+ # if item.content.extra_links is not None:
+ # links += item.content.extra_links
+ # if item.content.link_details is not None:
+ # links += [link.url for link in item.content.link_details]
+ #
+ # for link in links:
+ # link_host = urlparse(link).netloc
+ # self.redis.zincrby(HOST_COUNT_LINK_KEY.format(date=date), 1, link_host)
+ #
+ # if link not in url_db:
+ # self.redis.zincrby(HOST_COUNT_LINK_NEW_KEY.format(date=date), 1, link_host)
+ #
+ # self.redis.expire(host_key, SHORT_EXPIRE_SECONDS)
+ # self.redis.expire(host_all_key, SHORT_EXPIRE_SECONDS)
def get_stats(self) -> MwmblStats:
date_time = datetime.utcnow()