Skip to content

Commit dfc6065

Browse files
committed
update data storage
1 parent 5a814b7 commit dfc6065

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

code4me-server/src/api.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import annotations
2-
import os, time, random, json, uuid, glob, torch, traceback
2+
import os, time, random, json, uuid, torch, traceback
33

44
from enum import Enum
55
from typing import List, Tuple
@@ -182,7 +182,9 @@ def predict_model(model: Model) -> List[str]:
182182

183183
verify_token = uuid.uuid4().hex
184184

185-
with open(f"data/{user_token}-{verify_token}.json", "w+") as f:
185+
user_dir = os.path.join("data", user_token)
186+
os.makedirs(user_dir, exist_ok=True)
187+
with open(os.path.join(user_dir, f"{verify_token}.json"), "w+") as f:
186188
f.write(json.dumps({
187189
"completionTimestamp": datetime.now().isoformat(),
188190
"triggerPoint": values["triggerPoint"],
@@ -199,9 +201,8 @@ def predict_model(model: Model) -> List[str]:
199201
"rightContext": right_context if store_context else None
200202
}))
201203

202-
# # # TODO: disabled surveys temporarily, as we are currently looking through >1M files on every request.
203-
# n_suggestions = len(glob.glob(f"data/{user_token}*.json"))
204-
# survey = n_suggestions >= 100 and n_suggestions % 50 == 0
204+
n_suggestions = len(os.listdir(user_dir))
205+
survey = n_suggestions >= 100 and n_suggestions % 50 == 0
205206
survey = False
206207

207208
return response({
@@ -230,7 +231,7 @@ def verify():
230231
return res
231232

232233
verify_token = values["verifyToken"]
233-
file_path = f"data/{user_token}-{verify_token}.json"
234+
file_path = os.path.join("data", user_token, f"{verify_token}.json")
234235
if not os.path.exists(file_path):
235236
return response({
236237
"error": "Invalid verify token"

0 commit comments

Comments
 (0)