-
Notifications
You must be signed in to change notification settings - Fork 590
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
Documentation for the ExecutionStore #5144
Changes from 2 commits
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 |
---|---|---|
|
@@ -78,33 +78,21 @@ def has_store(self, store_name) -> bool: | |
|
||
def list_stores(self) -> list[str]: | ||
"""Lists the stores associated with the current context.""" | ||
result = self._collection.find( | ||
dict(key="__store__", dataset_id=self._dataset_id), | ||
{"store_name": 1}, | ||
) | ||
return [d["store_name"] for d in result] | ||
pipeline = [ | ||
{"$match": {"dataset_id": self._dataset_id}}, | ||
{"$group": {"_id": "$store_name"}}, | ||
] | ||
return [d["_id"] for d in self._collection.aggregate(pipeline)] | ||
|
||
def count_stores(self) -> int: | ||
"""Counts the stores associated with the current context.""" | ||
pipeline = [ | ||
{ | ||
"$match": { | ||
"dataset_id": self._dataset_id, | ||
} | ||
}, | ||
{ | ||
"$group": { | ||
"_id": { | ||
"store_name": "$store_name", | ||
"dataset_id": "$dataset_id", | ||
} | ||
} | ||
}, | ||
{"$count": "total_stores"}, | ||
{"$match": {"dataset_id": self._dataset_id}}, | ||
{"$group": {"_id": "$store_name", "count": {"$count": {}}}}, | ||
] | ||
|
||
result = list(self._collection.aggregate(pipeline)) | ||
return result[0]["total_stores"] if result else 0 | ||
return result[0]["count"] if result else 0 | ||
|
||
def delete_store(self, store_name) -> int: | ||
"""Deletes the specified store.""" | ||
|
@@ -233,9 +221,7 @@ def has_store_global(self, store_name): | |
"""Determines whether a store with the given name exists across all | ||
datasets and the global context. | ||
""" | ||
result = self._collection.find_one( | ||
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. Realized in testing that this method was broken |
||
dict(store_name=store_name, key="__store__"), {} | ||
) | ||
result = self._collection.find_one(dict(store_name=store_name), {}) | ||
return bool(result) | ||
|
||
def list_stores_global(self) -> list[StoreDocument]: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
) | ||
from .utils import ProgressHandler, is_new | ||
from .panel import Panel, PanelConfig | ||
from .store import ExecutionStore | ||
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. By convention, I prefer that anything that we're publicly documenting for users to be accessible via the highest reasonable package level. For example in this case: # happy
from fiftyone.operators import ExecutionStore
# sad; too low-level for end users
from fiftyone.operators.store import ExecutionStore 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. Add ExecutionStore to all to expose it properly. The Add this line before the from .store import ExecutionStore
from .categories import Categories
+ __all__ = ["ExecutionStore"] # Add this before the dynamic __all__ computation
# This enables Sphinx refs to directly use paths imported here
__all__ = [k for k, v in globals().items() if not k.startswith("_")]
🧰 Tools🪛 Ruff22-22: (F401) |
||
from .categories import Categories | ||
|
||
# This enables Sphinx refs to directly use paths imported here | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
| | ||
""" | ||
|
||
from datetime import datetime | ||
from typing import Any, Optional | ||
|
||
from bson import ObjectId | ||
|
@@ -101,19 +102,24 @@ def update_ttl(self, key: str, new_ttl: int) -> None: | |
""" | ||
self._store_service.update_ttl(self.store_name, key, new_ttl) | ||
|
||
def get_ttl(self, key: str) -> Optional[int]: | ||
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. Realized in testing that this method was broken |
||
"""Retrieves the TTL for a specific key. | ||
def get_metadata(self, key: str) -> Optional[datetime]: | ||
"""Retrieves the metadata for the given key. | ||
|
||
Args: | ||
key: the key to get the TTL for | ||
key: the key to check | ||
|
||
Returns: | ||
the TTL in seconds, or None if the key does not have a TTL | ||
a dict of metadata about the key | ||
""" | ||
key_doc = self._store_service.get_key(self.store_name, key) | ||
if key_doc is None: | ||
return None | ||
return key_doc.ttl | ||
|
||
return dict( | ||
created_at=key_doc.created_at, | ||
updated_at=key_doc.updated_at, | ||
expires_at=key_doc.expires_at, | ||
) | ||
brimoor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def list_keys(self) -> list[str]: | ||
"""Lists all keys in the store. | ||
|
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.
Realized in testing that this method was broken