Skip to content

Commit 0fc9b6e

Browse files
committed
Updated debug routes and changed redis db
1 parent 4a9c7a5 commit 0fc9b6e

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

backend/PyMatcha/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,11 @@ def expired_token_callback(expired_token):
154154
host=os.getenv("REDIS_HOST") if not os.getenv("IS_DOCKER_COMPOSE") else "redis",
155155
port=os.getenv("REDIS_PORT", 6379),
156156
decode_responses=True,
157+
db=2,
157158
)
158159

160+
redis.flushdb()
161+
159162
from PyMatcha.models.user import get_user
160163

161164

@@ -197,6 +200,7 @@ def check_if_token_is_revoked(decrypted_token):
197200
from PyMatcha.routes.api.like import like_bp
198201
from PyMatcha.routes.api.match import match_bp
199202
from PyMatcha.routes.api.messages import messages_bp
203+
from PyMatcha.routes.api.recommendations import recommendations_bp
200204

201205
logging.debug("Registering Flask blueprints")
202206
application.register_blueprint(user_bp)
@@ -211,6 +215,7 @@ def check_if_token_is_revoked(decrypted_token):
211215
application.register_blueprint(like_bp)
212216
application.register_blueprint(match_bp)
213217
application.register_blueprint(messages_bp)
218+
application.register_blueprint(recommendations_bp)
214219

215220
if application.debug:
216221
logging.debug("Registering debug route")

backend/PyMatcha/routes/api/debug.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
from PyMatcha.utils.decorators import debug_token_required
1919
from PyMatcha.utils.decorators import validate_params
2020
from PyMatcha.utils.errors import NotFoundError
21+
from PyMatcha.utils.populate_database import populate_users
2122
from PyMatcha.utils.success import Success
2223
from PyMatcha.utils.success import SuccessDeleted
24+
from PyMatcha.utils.tasks import update_user_recommendations
2325

2426
debug_bp = Blueprint("debug", __name__)
2527

@@ -72,13 +74,9 @@ def create_views(amount):
7274
@debug_bp.route("/debug/redis")
7375
@debug_token_required
7476
def debug_show_redis():
75-
ret = {"users": {}, "jtis": {}}
76-
for key in redis.scan_iter("user:*"):
77-
value = redis.get(str(key))
78-
ret["users"][key] = value
79-
for key in redis.scan_iter("jti:*"):
80-
value = redis.get(str(key))
81-
ret["jtis"][key] = value
77+
ret = dict()
78+
for key in redis.scan_iter("*"):
79+
ret[key] = redis.get(str(key))
8280
return jsonify(ret), 200
8381

8482

@@ -135,7 +133,7 @@ def create_fake_like():
135133

136134
@debug_bp.route("/debug/tables", methods=["DELETE"])
137135
@debug_token_required
138-
def delete_matches():
136+
def delete_tables():
139137
Match.drop_table()
140138
Like.drop_table()
141139
Report.drop_table()
@@ -154,6 +152,13 @@ def delete_matches():
154152
return "", 204
155153

156154

155+
@debug_bp.route("/debug/redis", methods=["DELETE"])
156+
@debug_token_required
157+
def delete_redis():
158+
redis.flushdb()
159+
return "", 204
160+
161+
157162
DEBUG_SEND_MESSAGE = {"from_uid": str, "to_uid": str, "content": str}
158163

159164

@@ -166,3 +171,12 @@ def debug_send_message():
166171
to_id = get_user(data["to_uid"]).id
167172
Message.create(from_id=from_id, to_id=to_id, content=data["content"])
168173
return "", 204
174+
175+
176+
@debug_bp.route("/debug/recommendations/start", methods=["POST"])
177+
@debug_token_required
178+
def debug_recommendations_start_process():
179+
"""This function will create 100 random users and calculate recommendations"""
180+
populate_users(amount=100, drop_user_table=False)
181+
update_user_recommendations()
182+
return Success("Done")

0 commit comments

Comments
 (0)