ishaan1013 / sandbox

A cloud-based code editing environment with an AI copilot and real-time collaboration
MIT License
1.29k stars 104 forks source link

Debounce file saving #13

Open ishaan1013 opened 4 months ago

ishaan1013 commented 4 months ago

We currently update Cloudflare R2 on every file save.

Implementing debouncing would reduce # of queries when a user frequently saves the same file.

akhilkh2000 commented 4 months ago

@ishaan1013 - First of all kudos to you for creating such an amazing project!!, was really nice to use and try my hand at a contribution. Have raised a PR for this, let me know if that looks good. Also, had noticed a couple of issues / observations that we could discuss that can be raised as separate issues:

(Will raise the below if needed as separate issue tickets later this week)

  1. I see that each key press gets sent to liveblocks so , we might need debouncing around that as well (unless thats a default unchangeable behavior of liveblocks itself)

  2. Playing around with the editor and typing in it results in thousands of socket XHR requests , not sure if that is by design

image


After sometime I see these errors on the console image

  1. Also, one error I ran into while testing my change was if "undefined" is passed as the file content to the backend , it returns a rate limiter error as the catch all exception block just sends that by default which might be a little misleading as its not actually a rate limit issue

image

akhilkh2000 commented 4 months ago

Also, Im not very well versed with CF but in about a day, looking at the metrics, it looks like there is room for optimizing the number of requests to CF (other than the debouncing) as well? What do you think?

image

ishaan1013 commented 4 months ago

Great points. In all honesty I didn't do a ton of testing and I noticed a few of the issues you mentioned, although not specifically to this extent. There's definitely a ton of room for optimization, so feel free to continue looking into it and keep me updated! I'd love to hear about your journey through this and help you out along the way.

akhilkh2000 commented 3 months ago

@ishaan1013 yeah, will try looking at it sometime next week. Btw, does the pr look good to merge? Let me know if there is any issues with it