Silverfeelin / SkyGame-Planner

Sky:CotL unlock planner/tracker
Other
17 stars 3 forks source link

Closet link duration #49

Closed Silverfeelin closed 2 months ago

Silverfeelin commented 7 months ago

Copying a closet link will use Cloudflare KV to store the selected items since the selection can range from 1 to all items (which can not be handled through the query string).

Right now these links last one day. Since Cloudflare KV offers a 1 GB limit the timer doesn't have to be this short, although it remains that keys would eventually be deleted. This means looking up old requests (fulfilled or not) would show an empty selection.

Issue will remain open until there's a good plan.

Some ideas:

PlutoyDev commented 2 months ago

According to this stack overflow answer, the recommended limit of the URL is 2000 characters.

The origin and the path to outfit request are 52 characters. 4x query param with empty data takes 12 characters. So, for data, we are left with 1936 characters and that is 645 items.

Personally, I avoid using any backend for side projects and will shift into the client.

Slight Changes

Maybe instead of displaying empty selection. Have a pop-up / model stating that the link is invalid or expired, asking user to request for the link again from requester.

Method 1 (Limit)

Limit it to 645 items. Prevent users from creating adding more. Imo, I don't know if anyone needs more than that. The application gets a bit laggy when I added all item :), or maybe it's just my computer.

Method 2 (Compression)

With client-side library like fflate, about 8kb, can potentially give a compression of 2:1, giving twice (untested) the number of items that can be stored in URL. Sorting the ids before serializing resulting in more similar string, giving a higher compression ratio.

Method 3 (Cloudflare KV, with time limit)

Prefix 2-digit day value in the ID I think 3d is safe enough. maybe restart the expiration every day it read by writing a same value with a new expiration that is 3d from read.

FYI, my brutal test :)

Silverfeelin commented 2 months ago

@PlutoyDev This actually didn't turn out to be as much of a problem. 99% of the outfit request usage is through copying the screenshot and not a link. I'm currently sitting at 10-15 writes a day of the 1000 free limit. Since the outfit request channel isn't magically seeing a growth of 100x the only concern is storage.

Going by the current data (which I set to 1 week expiry instead of 1 day a while ago) KV is sitting at 87 kB/1 GB for 91 entries. So I could quite safely increase the lifetime but there is little point right now.

image

Still, there's a few things I want to elaborate on.

Maybe instead of displaying empty selection. Have a pop-up / model stating that the link is invalid or expired, asking user to request for the link again from requester.

Definitely going to do this! I'll make a new issue for this in a minute.

So, for data, we are left with 1936 characters and that is 645 items. Method 1 (Limit)

Although it is possible to store more data in the link, for sharing requests these links are typically shared in the outfit-requests channel on Skycord. Which means that 645 items being a totally reasonable hard limit for the website, it's going to be a problem when putting this link in a request. Discord has its own message limit of 2000 characters meaning any characters wasted on a large URL would limit the context people can add in their messages. Plus it just looks ugly to share such a long link (even though I could mask it using markdown, then it wouldn't work as a direct link anywhere else).

Method 2 (Compression)

I provide a unique ID (number) for every item and encode these to base36 so they're about as short as I can make them while being URL-safe. With a fixed length of 3 characters so I don't need a delimiter this gives me an upper limit of 46656 minus a few reserved. Which will be enough to keep it working indefinitely. I'm not sure how I'd make compressed binary data using a library like fflate URL safe. Alphanumeric is already pretty close to the limit of URL safe characters that don't require % encoding.

Method 3 (Cloudflare KV, with time limit)

This is what I use right now when you use the copy link button. Which is how you're supposed to share your closet or an outfit request. The URL you shared is not what's being copied and I simply use that to remember the current selection when you navigate away or bookmark the page. I think it's fine if that part is not compatible with >600 items.

Silverfeelin commented 2 months ago

I'm going to close this as not planned. I've bumped the TTL to 31 days and if usage shifts over time I'll reconsider the options.