casual-simulation / casualos

Casual Open Simulation for the Web
https://ab1.bot
MIT License
49 stars 9 forks source link

Saving a private inst fails if the merged update is too large #476

Open KallynGowdy opened 5 months ago

KallynGowdy commented 5 months ago

When running this AUX, a private inst will build up so many updates that it becomes impossible for the server to save them to the database. Ideally, the server should be able to save private insts, regardless of the number of updates.

AUX File:

{"version":1,"state":{"undefined":{"id":"12314b5d-3bd2-44cb-9559-09f0204cf10c","space":"shared","tags":{"home":true,"homeX":-8,"homeY":2,"color":"#00ffb7","myJson":":dna:{\n  \"user_id\": 1,\n  \"username\": \"john_doe\",\n  \"email\": \"john.doe@example.com\",\n  \"age\": 30,\n  \"is_active\": true,\n  \"balance\": 2450.75,\n  \"address\": {\n    \"street\": \"1234 Main St\",\n    \"city\": \"Anytown\",\n    \"state\": \"CA\",\n    \"zipcode\": \"90210\"\n  },\n  \"preferences\": {\n    \"newsletter\": false,\n    \"notifications\": true,\n    \"themes\": [\"dark\", \"light\"]\n  },\n  \"login_count\": 150,\n  \"last_login\": \"2024-05-10T12:45:00Z\",\n  \"registered_on\": \"2020-01-01T00:00:00Z\",\n  \"profile_complete\": 85,\n  \"tags\": [\"user\", \"active\", \"premium\"],\n  \"order_history\": [\n    {\"order_id\": \"A001\", \"date\": \"2024-04-25\", \"amount\": 199.99},\n    {\"order_id\": \"A002\", \"date\": \"2024-05-01\", \"amount\": 89.95}\n  ],\n  \"credit_card\": {\n    \"number\": \"4111111111111111\",\n    \"expiry\": \"12/24\",\n    \"cvv\": \"123\"\n  },\n  \"achievement_scores\": {\n    \"game\": 1200,\n    \"app\": 300,\n    \"total\": 1500\n  },\n  \"subscription_active\": true,\n  \"subscription_plan\": \"premium\",\n  \"due_amount\": 0.0,\n  \"payments\": [\n    {\"date\": \"2024-01-01\", \"amount\": 15.0, \"method\": \"credit_card\"},\n    {\"date\": \"2024-02-01\", \"amount\": 15.0, \"method\": \"paypal\"}\n  ],\n  \"bio\": \"Just a regular person interested in tech.\",\n  \"education\": {\n    \"high_school\": \"Central High\",\n    \"college\": \"State University\",\n    \"degree\": \"BSc Computer Science\"\n  },\n  \"work_experience\": [\n    {\"company\": \"TechCorp\", \"position\": \"Developer\", \"years\": 3},\n    {\"company\": \"WebSolutions\", \"position\": \"Senior Developer\", \"years\": 2}\n  ],\n  \"skills\": [\"JavaScript\", \"Python\", \"React\", \"Node.js\"],\n  \"languages_spoken\": [\"English\", \"Spanish\"],\n  \"country_of_residence\": \"USA\",\n  \"time_zone\": \"PST\",\n  \"has_pets\": false,\n  \"pet_details\": {\n    \"pet_type\": \"none\"\n  },\n  \"favorite_music\": [\"rock\", \"jazz\", \"classical\"],\n  \"favorite_movies\": [\"Inception\", \"The Matrix\", \"Interstellar\"],\n  \"hobbies\": [\"reading\", \"gaming\", \"hiking\"],\n  \"volunteer_work\": [\n    {\"organization\": \"Local Library\", \"role\": \"Tutor\", \"years\": 2}\n  ],\n  \"medical_history\": {\n    \"allergies\": [\"none\"],\n    \"medications\": [\"none\"]\n  },\n  \"diet_preferences\": \"vegetarian\",\n  \"favorite_books\": [\"1984\", \"Brave New World\", \"Fahrenheit 451\"],\n  \"social_media\": {\n    \"facebook\": \"john.doe\",\n    \"twitter\": \"@johndoe\",\n    \"instagram\": \"john_doe_insta\"\n  },\n  \"vehicle\": {\n    \"make\": \"Toyota\",\n    \"model\": \"Camry\",\n    \"year\": 2022\n  },\n  \"member_since\": \"2018-01-01\",\n  \"last_purchase\": \"2024-04-25\",\n  \"favorite_sports\": [\"basketball\", \"soccer\"],\n  \"children\": 0,\n  \"marital_status\": \"single\",\n  \"legal_status\": \"citizen\"\n}\n","onClick":"@let jsonObject = tags.myJson;\n\nfunction generateRandomCardNumber() {\n    // This function generates a 16-digit random number\n    let cardNumber = '';\n    for (let i = 0; i < 16; i++) {\n        cardNumber += Math.floor(Math.random() * 10).toString();\n    }\n    return cardNumber;\n}\n\nfor (let i = 0; i < 10000; i++) {\n    jsonObject = {...jsonObject}\n    jsonObject.credit_card.number = generateRandomCardNumber();\n    tags.myJson = jsonObject;\n    console.log(`Update ${i + 1}: New card number - ${jsonObject.credit_card.number}`);\n    await os.sleep(10);\n}\n"}}}}
KallynGowdy commented 4 months ago

This might still be possible, but is much less likely now that updates get merged and garbage collected correctly.