Skip to content

Commit b71023d

Browse files
committed
fix: refactor re, optimize regular exsperssion, fix bug with cache
1 parent 02aebb7 commit b71023d

4 files changed

Lines changed: 7 additions & 4 deletions

File tree

backend/yet_another_calendar/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Settings(BaseSettings):
5050
redis_events_time_live: int = 60 * 60 * 24 * 14 # 2 weeks
5151
redis_utmn_teachers_time_live: int = 60 * 60 * 24 * 30 # 30 days
5252
redis_prefix: str = 'FastAPI-redis'
53+
redis_lesson_prefix: str = "calendar"
5354

5455
retry_tries: int = 5
5556
retry_delay: int = 3

backend/yet_another_calendar/tests/test_netology.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ async def test_lesson_webinar_schema() -> None:
220220
("Submit by 00.04.24", (2024, 4, 1)),
221221
("Submit by 00..04..24", (2024, 4, 1)),
222222
("Submit by 01.04.2025", (2025, 4, 1)),
223+
("Submit by 01.04.2025", (2025, 4, 1)),
224+
("Домашнее задание 8 (тест) к теме 10 «Ядро и уровень пользователя» (дедлайн 22.05.25)", (2025, 5, 22)),
223225
])
224226
@pytest.mark.asyncio
225227
async def test_lesson_task_schema_validation(title: str, date: tuple[int, int, int] | None) -> None:

backend/yet_another_calendar/web/api/bulk/integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async def refresh_events(
101101
coder = FastAPICache.get_coder()
102102
backend = FastAPICache.get_backend()
103103
await backend.set(
104-
key=f"{settings.redis_prefix}:{cache_key}",
104+
key=f"{settings.redis_prefix}:{settings.redis_lesson_prefix}{cache_key}",
105105
value=coder.encode(calendar),
106106
expire=settings.redis_events_time_live)
107107
except Exception as exception:
@@ -140,7 +140,7 @@ async def get_calendar(
140140
@cache(
141141
expire=settings.redis_events_time_live,
142142
key_builder=key_builder,
143-
namespace="calendar",
143+
namespace=settings.redis_lesson_prefix,
144144
) # type i
145145
async def get_cached_calendar(
146146
body: modeus_schema.ModeusTimeBody,

backend/yet_another_calendar/web/api/netology/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from yet_another_calendar.web.api.modeus.schema import ModeusTimeBody
1212
from yet_another_calendar.web.api.validators import OptionalUTCDate
1313

14-
_DATE_PATTERN = r"(?<!\d)(\d{2})\D+(\d{2})\D+(?:\d{2})?(\d{2})(?!\d)"
14+
_DATE_PATTERN = re.compile(r"(?<!\d)(\d{2})[^\w]+(\d{2})[^\w]+(?:\d{2})?(\d{2})(?!\d)")
1515

1616
class NetologyCreds(BaseModel):
1717
"""Netology creds."""
@@ -106,7 +106,7 @@ def deadline_validation(cls, data: Any) -> Any:
106106
if not isinstance(data, dict):
107107
return data
108108
title = str(data.get('title', ''))
109-
match = re.search(_DATE_PATTERN, title)
109+
match = _DATE_PATTERN.search(title)
110110
if not match:
111111
return data
112112
try:

0 commit comments

Comments
 (0)