-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #298 from OP-TED/feature/TED-822
notice collection mat view
- Loading branch information
Showing
2 changed files
with
58 additions
and
19 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
ted_sws/data_manager/services/create_notice_collection_materialised_view.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from pymongo import MongoClient, ASCENDING, DESCENDING | ||
|
||
from ted_sws import config | ||
|
||
NOTICE_COLLECTION_NAME = "notice_collection" | ||
NOTICES_MATERIALISED_VIEW_NAME = "notices_collection_materialised_view" | ||
|
||
|
||
def create_notice_collection_materialised_view(mongo_client: MongoClient): | ||
database = mongo_client[config.MONGO_DB_AGGREGATES_DATABASE_NAME or "aggregates_db"] | ||
notice_collection = database[NOTICE_COLLECTION_NAME] | ||
notice_collection.aggregate([ | ||
{ | ||
"$project": { | ||
"_id": True, | ||
"created_at": True, | ||
"status": True, | ||
"validation_summary": True, | ||
"version_number": True, | ||
"form_number": "$normalised_metadata.form_number", | ||
"form_type": "$normalised_metadata.form_type", | ||
"eu_institution": "$normalised_metadata.eu_institution", | ||
"extracted_legal_basis_directive": "$normalised_metadata.extracted_legal_basis_directive", | ||
"ojs_type": "$normalised_metadata.ojs_type", | ||
"legal_basis_directive": "$normalised_metadata.legal_basis_directive", | ||
"country_of_buyer": "$normalised_metadata.country_of_buyer", | ||
"eforms_subtype": "$normalised_metadata.eforms_subtype", | ||
"notice_type": "$normalised_metadata.notice_type", | ||
"xsd_version": "$normalised_metadata.xsd_version", | ||
"publication_date": "$normalised_metadata.publication_date", | ||
} | ||
}, { | ||
"$merge": { | ||
"into": NOTICES_MATERIALISED_VIEW_NAME | ||
} | ||
} | ||
]) | ||
materialised_view = database[NOTICES_MATERIALISED_VIEW_NAME] | ||
materialised_view.create_index([("created_at", DESCENDING)]) | ||
materialised_view.create_index([("publication_date", DESCENDING)]) | ||
materialised_view.create_index([("eu_institution", ASCENDING)]) | ||
materialised_view.create_index([("status", ASCENDING)]) | ||
materialised_view.create_index([("form_number", ASCENDING)]) | ||
materialised_view.create_index([("form_number", ASCENDING), ("status", ASCENDING)]) | ||
materialised_view.create_index([("form_number", ASCENDING), ("legal_basis_directive", ASCENDING)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters