-
-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathutils.py
More file actions
48 lines (39 loc) · 1.23 KB
/
utils.py
File metadata and controls
48 lines (39 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
from tortoise import Tortoise
from ballsdex.__main__ import init_tortoise
from ballsdex.core.models import (
Ball,
CardTemplate,
Economy,
Regime,
Special,
balls,
card_templates,
economies,
regimes,
specials,
)
async def refresh_cache():
"""
Similar to the bot's `load_cache` function without the fancy display. Also handles
initializing the connection to Tortoise.
This must be called on every request, since the image generation relies on cache and we
do *not* want caching in the admin panel to happen (since we're actively editing stuff).
"""
if not Tortoise._inited:
await init_tortoise(os.environ["BALLSDEXBOT_DB_URL"], skip_migrations=True)
balls.clear()
for ball in await Ball.all():
balls[ball.pk] = ball
regimes.clear()
for regime in await Regime.all():
regimes[regime.pk] = regime
economies.clear()
for economy in await Economy.all():
economies[economy.pk] = economy
specials.clear()
for special in await Special.all():
specials[special.pk] = special
card_templates.clear()
for card_template in await CardTemplate.all():
card_templates[card_template.pk] = card_template