-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve #32 by using revision cache more efficiently
- Loading branch information
Showing
10 changed files
with
157 additions
and
45 deletions.
There are no files selected for viewing
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
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
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,64 @@ | ||
import logging | ||
from typing import Optional | ||
|
||
from pymongo import ASCENDING, DESCENDING | ||
|
||
from bci.database.mongo.mongodb import MongoDB | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class RevisionCache: | ||
@staticmethod | ||
def store_firefox_binary_availability(data: dict) -> None: | ||
values = list(data.values()) | ||
collection = MongoDB.get_instance().db['firefox_binary_availability'] | ||
|
||
if (n := len(values)) == collection.count_documents({}): | ||
logger.debug(f'Reivision Cache was not updated ({n} documents).') | ||
return | ||
|
||
collection.delete_many({}) | ||
collection.insert_many(values) | ||
logger.info(f'Revision Cache was updates ({len(values)} documents).') | ||
|
||
@staticmethod | ||
def firefox_get_revision_number(revision_id: str) -> int: | ||
collection = MongoDB.get_instance().db['firefox_binary_availability'] | ||
result = collection.find_one({'revision_id': revision_id}, {'revision_number': 1}) | ||
return result['revision_number'] | ||
|
||
@staticmethod | ||
def firefox_has_binary_for(revision_nb: Optional[int], revision_id: Optional[str]) -> bool: | ||
collection = MongoDB.get_instance().db['firefox_binary_availability'] | ||
if revision_nb: | ||
result = collection.find_one({'revision_number': revision_nb}) | ||
elif revision_id: | ||
result = collection.find_one({'revision_number': revision_nb}) | ||
else: | ||
raise AttributeError('No revision number or id was provided') | ||
return result is not None | ||
|
||
@staticmethod | ||
def firefox_get_binary_info(revision_id: str) -> dict: | ||
collection = MongoDB.get_instance().db['firefox_binary_availability'] | ||
return collection.find_one({'revision_id': revision_id}, {'files_url': 1, 'app_version': 1}) | ||
|
||
@staticmethod | ||
def firefox_get_previous_and_next_revision_nb_with_binary(revision_nb: int) -> tuple[int, int]: | ||
collection = MongoDB.get_instance().db['firefox_binary_availability'] | ||
|
||
previous_revision_nbs = collection.find({'revision_number': {'$lt': revision_nb}}).sort( | ||
{'revision_number': DESCENDING} | ||
) | ||
previous_document = next(previous_revision_nbs, None) | ||
|
||
next_revision_nbs = collection.find({'revision_number': {'$gt': revision_nb}}).sort( | ||
{'revision_number': ASCENDING} | ||
) | ||
next_document = next(next_revision_nbs, None) | ||
|
||
return ( | ||
previous_document['revision_number'] if previous_document else None, | ||
next_document['revision_number'] if next_document else None, | ||
) |
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
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
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
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
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
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
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