mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-07 01:42:30 -05:00
[V3 Config] Update Mongo document organization to bypass doc size restriction (#2536)
* modify config to use identifier data class and update json driver * move identifier data attributes into read only properties * Update mongo get and set methods * Update get/set to use UUID separately, make clear work * Remove not implemented and fix get_raw * Update remaining untouched get/set/clear * Fix get_raw * Finally fix get_raw and set_raw * style * This is better * Sorry guys * Update get behavior to handle "all" calls as expected * style again * Why do you do this to me * style once more * Update mongo schema
This commit is contained in:
@@ -1,4 +1,51 @@
|
||||
__all__ = ["BaseDriver"]
|
||||
from typing import Tuple
|
||||
|
||||
__all__ = ["BaseDriver", "IdentifierData"]
|
||||
|
||||
|
||||
class IdentifierData:
|
||||
def __init__(self, uuid: str, category: str, primary_key: Tuple[str], identifiers: Tuple[str]):
|
||||
self._uuid = uuid
|
||||
self._category = category
|
||||
self._primary_key = primary_key
|
||||
self._identifiers = identifiers
|
||||
|
||||
@property
|
||||
def uuid(self):
|
||||
return self._uuid
|
||||
|
||||
@property
|
||||
def category(self):
|
||||
return self._category
|
||||
|
||||
@property
|
||||
def primary_key(self):
|
||||
return self._primary_key
|
||||
|
||||
@property
|
||||
def identifiers(self):
|
||||
return self._identifiers
|
||||
|
||||
def __repr__(self):
|
||||
return (
|
||||
f"<IdentifierData uuid={self.uuid} category={self.category} primary_key={self.primary_key}"
|
||||
f" identifiers={self.identifiers}>"
|
||||
)
|
||||
|
||||
def add_identifier(self, *identifier: str) -> "IdentifierData":
|
||||
if not all(isinstance(i, str) for i in identifier):
|
||||
raise ValueError("Identifiers must be strings.")
|
||||
|
||||
return IdentifierData(
|
||||
self.uuid, self.category, self.primary_key, self.identifiers + identifier
|
||||
)
|
||||
|
||||
def to_tuple(self):
|
||||
return tuple(
|
||||
item
|
||||
for item in (self.uuid, self.category, *self.primary_key, *self.identifiers)
|
||||
if len(item) > 0
|
||||
)
|
||||
|
||||
|
||||
class BaseDriver:
|
||||
@@ -6,14 +53,13 @@ class BaseDriver:
|
||||
self.cog_name = cog_name
|
||||
self.unique_cog_identifier = identifier
|
||||
|
||||
async def get(self, *identifiers: str):
|
||||
async def get(self, identifier_data: IdentifierData):
|
||||
"""
|
||||
Finds the value indicate by the given identifiers.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
identifiers
|
||||
A list of identifiers that correspond to nested dict accesses.
|
||||
identifier_data
|
||||
|
||||
Returns
|
||||
-------
|
||||
@@ -33,20 +79,19 @@ class BaseDriver:
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
async def set(self, *identifiers: str, value=None):
|
||||
async def set(self, identifier_data: IdentifierData, value=None):
|
||||
"""
|
||||
Sets the value of the key indicated by the given identifiers.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
identifiers
|
||||
A list of identifiers that correspond to nested dict accesses.
|
||||
identifier_data
|
||||
value
|
||||
Any JSON serializable python object.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
async def clear(self, *identifiers: str):
|
||||
async def clear(self, identifier_data: IdentifierData):
|
||||
"""
|
||||
Clears out the value specified by the given identifiers.
|
||||
|
||||
@@ -54,7 +99,6 @@ class BaseDriver:
|
||||
|
||||
Parameters
|
||||
----------
|
||||
identifiers
|
||||
A list of identifiers that correspond to nested dict accesses.
|
||||
identifier_data
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
Reference in New Issue
Block a user