Adding view count and like button to 11ty
annoyscript.vercel.app
Adding view count and like button to 11ty
1–10 of 13 posts
Re: Adding view count and like button to 11ty
#2Re: Adding view count and like button to 11ty
#3There doesn't seem to be a limit to how many times a reader can smash that like button, which brings a new degree of expression to smashing that like. You can smash that like 10 times the article was good, 100 times if it was amazing, or 100 million times if you hated it and want the author to be bankrupted by their Vercel bill.
Re: Adding view count and like button to 11ty
#4Re: Adding view count and like button to 11ty
#5There doesn't seem to be a limit to how many times a reader can smash that like button, which brings a new degree of expression to smashing that like. You can smash that like 10 times the article was good, 100 times if it was amazing, or 100 million times if you hated it and want the author to be bankrupted by their Vercel bill.
As I mentioned in the blog, I have a free tier, so I just got an email from Vercel that KV will stop accepting new request for today.
Re: Adding view count and like button to 11ty
#6The HSET calls are not just unnecessary, they're a bug. It introduces the possibility of a race condition where a view or like happens between the HGET and HSET. HSETing the values to zero doesn't actually make anything faster or more correct, it just introduces the possibility of overwriting a value that came in moments ago.
Re: Adding view count and like button to 11ty
#7There doesn't seem to be a limit to how many times a reader can smash that like button, which brings a new degree of expression to smashing that like. You can smash that like 10 times the article was good, 100 times if it was amazing, or 100 million times if you hated it and want the author to be bankrupted by their Vercel bill.
are you the one that is actually DDoSing my Vercel KV lol? I had like 5k requests in the last few hours ^^ As I mentioned in the blog, I have a free tier, so I just got an email from Vercel that KV will stop accepting new request for today.
Re: Adding view count and like button to 11ty
#8Earlier quoted context omitted.
are you the one that is actually DDoSing my Vercel KV lol? I had like 5k requests in the last few hours ^^ As I mentioned in the blog, I have a free tier, so I just got an email from Vercel that KV will stop accepting new request for today.
(I work at Vercel) You can set up the Vercel Firewall to block traffic: https://vercel.com/docs/security/vercel-waf/custom-rules
Re: Adding view count and like button to 11ty
#9The HSET calls are not just unnecessary, they're a bug. It introduces the possibility of a race condition where a view or like happens between the HGET and HSET. HSETing the values to zero doesn't actually make anything faster or more correct, it just introduces the possibility of overwriting a value that came in moments ago.
so how would you approach this?
Re: Adding view count and like button to 11ty
#10Earlier quoted context omitted.
so how would you approach this?
Just do hincrby alone, if it doesn't exist it will automatically become 1
Get:
const likes = (await kv.hget(postTitle, "likes")) || 0
Post: const likes = await kv.hincrby(postTitle, "likes", 1);