mirror of
https://github.com/ltcptgeneral/cs239-caching.git
synced 2025-11-21 08:15:08 +00:00
Deepseek data generation
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
|
||||
from tinydb import TinyDB, Query
|
||||
from generate_data import generate_data
|
||||
|
||||
# Initialize TinyDB as a NoSQL key-value store
|
||||
DB_FILE = "database.json"
|
||||
@@ -11,9 +12,9 @@ def get_user_profile(user_id):
|
||||
result = db.search(User.user_id == user_id)
|
||||
return result[0] if result else None
|
||||
|
||||
def update_user_profile(user_id, name, followers, bio, posts):
|
||||
def update_user_profile(user_id, name, followers, bio, posts, friends):
|
||||
"""Update user profile in TinyDB"""
|
||||
db.upsert({"user_id": user_id, "name": name, "followers": followers, "bio": bio, "posts": posts}, User.user_id == user_id)
|
||||
db.upsert({"user_id": user_id, "name": name, "followers": followers, "bio": bio, "posts": posts, "friends": friends}, User.user_id == user_id)
|
||||
|
||||
def init_db():
|
||||
"""Ensure TinyDB is initialized before FastAPI starts and prepopulate some data"""
|
||||
@@ -22,8 +23,5 @@ def init_db():
|
||||
|
||||
# Prepopulate database with some sample users if empty
|
||||
if len(db) == 0:
|
||||
db.insert_multiple([
|
||||
{"user_id": "1", "name": "Alice", "followers": 100, "bio": "Love coding!", "posts": "Hello, world!"},
|
||||
{"user_id": "2", "name": "Bob", "followers": 200, "bio": "Tech enthusiast", "posts": "AI is amazing!"},
|
||||
{"user_id": "3", "name": "Charlie", "followers": 50, "bio": "Blogger", "posts": "Check out my latest post!"}
|
||||
])
|
||||
data = generate_data(100)
|
||||
db.insert_multiple(data)
|
||||
|
||||
Reference in New Issue
Block a user