-
-
Notifications
You must be signed in to change notification settings - Fork 54
compute top page origins for each collection #2483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2e3a6af
027d73f
20b72b4
5c81dc0
a999258
5b774a3
96d705c
5a39925
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
Migration 0044 - Recalculate collection stats | ||
""" | ||
|
||
from btrixcloud.migrations import BaseMigration | ||
|
||
|
||
MIGRATION_VERSION = "0044" | ||
|
||
|
||
# pylint: disable=duplicate-code | ||
class Migration(BaseMigration): | ||
"""Migration class.""" | ||
|
||
# pylint: disable=unused-argument | ||
def __init__(self, mdb, **kwargs): | ||
super().__init__(mdb, migration_version=MIGRATION_VERSION) | ||
|
||
self.coll_ops = kwargs.get("coll_ops") | ||
|
||
async def migrate_up(self): | ||
"""Perform migration up. | ||
|
||
Recalculate collection stats to get top host names | ||
""" | ||
colls_mdb = self.mdb["collections"] | ||
|
||
if self.coll_ops is None: | ||
print( | ||
"Unable to set collection stats, missing coll_ops", | ||
flush=True, | ||
) | ||
return | ||
|
||
async for coll in colls_mdb.find({}): | ||
coll_id = coll["_id"] | ||
try: | ||
await self.coll_ops.update_collection_counts_and_tags(coll_id) | ||
# pylint: disable=broad-exception-caught | ||
except Exception as err: | ||
print( | ||
f"Unable to update page stats for collection {coll_id}: {err}", | ||
flush=True, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1417,6 +1417,14 @@ class PreloadResource(BaseModel): | |
crawlId: str | ||
|
||
|
||
# ============================================================================ | ||
class HostCount(BaseModel): | ||
"""Host Count""" | ||
|
||
host: str | ||
count: int | ||
|
||
|
||
# ============================================================================ | ||
class Collection(BaseMongoModel): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we include There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, perhaps can rename this to domains internally too? We can strip out the https:// with the regex too, but maybe useful to keep since RWP does treat them separately.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah not a bad idea to rename internally, and I would keep the prefix I think |
||
"""Org collection structure""" | ||
|
@@ -1515,6 +1523,8 @@ class CollOut(BaseMongoModel): | |
pagesQueryUrl: str = "" | ||
downloadUrl: Optional[str] = None | ||
|
||
topPageHosts: List[HostCount] = [] | ||
|
||
|
||
# ============================================================================ | ||
class PublicCollOut(BaseMongoModel): | ||
|
@@ -1550,6 +1560,8 @@ class PublicCollOut(BaseMongoModel): | |
|
||
allowPublicDownload: bool = True | ||
|
||
topPageHosts: List[HostCount] = [] | ||
|
||
|
||
# ============================================================================ | ||
class UpdateColl(BaseModel): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like maybe the migration that goes with this version bump hasn't been committed?