Skip to content

Commit c6eb5e7

Browse files
committed
Implmeent RAM Cache (partially)
1 parent e92a062 commit c6eb5e7

4 files changed

Lines changed: 15 additions & 22 deletions

File tree

helpful_modules/problems_module/AbstractKVCache.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ async def del_all_by_user_id(self, user_id: int) -> None:
127127
continue
128128
if belongs:
129129
await self.remove_thing(key)
130-
@abstractmethod
131130
async def delete_all_by_guild_id(self, guild_id: int) -> None:
132131
all_items = await self.items()
133132
for key, value in all_items:
@@ -137,10 +136,8 @@ async def delete_all_by_guild_id(self, guild_id: int) -> None:
137136
continue
138137
if belongs:
139138
await self.remove_thing(key)
140-
@abstractmethod
141139
async def get_all_items_starting_with(self, thing_start: str) -> list[tuple[str, IdentifiableDictConvertible]]:
142140
return list(filter(lambda tu: tu[0].startswith(thing_start), await self.items()))
143-
@abstractmethod
144141
async def get_appeal_view_infos(self) -> list[AppealViewInfo]:
145142
"""
146143
Retrieve all appeal view information stored in Redis.

helpful_modules/problems_module/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
# Author: Samuel Guo (64931063+rf20008@users.noreply.github.com)
2727

2828
from . import *
29+
from .errors import *
2930
from .appeal import Appeal, AppealViewInfo, AppealType
3031
from .appeal_question import AppealQuestion, APPEAL_QUESTION_TYPE_NAMES
3132
from .base_problem import BaseProblem
@@ -34,7 +35,7 @@
3435
from .computational_problem import ComputationalProblem
3536
from .denylistable import Denylistable, DenylistType, DenylistMetadata
3637
from .dict_convertible import DictConvertible
37-
from .errors import *
38+
3839
from .GuildData import CheckForUserPassage, GuildData
3940
from .linear_algebra_problem import LinearAlgebraProblem
4041
from .parse_problem import convert_dict_to_problem, convert_row_to_problem

helpful_modules/problems_module/cache_ABC.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
from .errors import (
3535
FormatException,
3636
SQLNotSupportedInRedisException,
37-
ThingNotFound
37+
ThingNotFound,
38+
ProblemNotFound,
39+
QuizNotFound,
40+
AppealViewInfoNotFound
3841
)
3942
from .GuildData import GuildData
4043
from .quizzes import Quiz

helpful_modules/problems_module/cache_rewrite_with_redis/NewRedisCache.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,19 @@
2121
2222
Author: Samuel Guo (64931063+rf20008@users.noreply.github.com)
2323
"""
24-
from abc import ABC, abstractmethod
24+
from abc import ABC
2525
import typing
26-
from typing import List
27-
import warnings
2826
import orjson
2927
import asyncio
30-
from ...FileDictionaryReader import AsyncFileDict
31-
from ..appeal import Appeal, AppealViewInfo
32-
from ..base_problem import BaseProblem
33-
from ..dict_convertible import DictConvertible, IdentifiableDictConvertible
28+
from helpful_modules.FileDictionaryReader import AsyncFileDict
29+
from helpful_modules.problems_module.dict_convertible import DictConvertible, IdentifiableDictConvertible
3430
from redis import asyncio as aioredis # type: ignore
35-
from ..errors import (
36-
FormatException,
37-
SQLNotSupportedInRedisException, ThingNotFound,
38-
CorruptedDataException, OwnershipNotDeterminableException
31+
from helpful_modules.problems_module.errors import (
32+
SQLNotSupportedInRedisException,
33+
ThingNotFound,
34+
CorruptedDataException,
35+
OwnershipNotDeterminableException
3936
)
40-
from ..GuildData import GuildData
41-
from ..quizzes import Quiz
42-
from ..user_data import UserData
43-
from ..verification_code_info import VerificationCodeInfo
4437
from ..AbstractKVCache import AbstractKVBasedCache, PREFIX_REGISTRY
4538
from ..cache_ABC import TYPE_ERROR_NOT_FOUND
4639
MUST_IMPLEMENT_ERROR = NotImplementedError("Subclasses must implement this")
@@ -87,7 +80,6 @@ def __init__(self, redis_url: str, password: str) -> None:
8780
self.lock = asyncio.Lock()
8881

8982

90-
@abstractmethod
9183
async def get_all_things(self) -> list[IdentifiableDictConvertible]:
9284
"""Return a list of EVERYTHING in the database"""
9385
return [value for key, value in await self.items()]
@@ -372,4 +364,4 @@ async def initialize_sql_table(self):
372364
"SQL is not supported in Redis, and creating sql tables is not supported in Redis either"
373365
)
374366
if __name__ == "__main__":
375-
r = RedisCache2()
367+
g r = RedisCache2()

0 commit comments

Comments
 (0)