N
N
nakem2022-01-21 10:26:48
go
nakem, 2022-01-21 10:26:48

How can I set up daily limits for telegram bot users?

I want to set up daily limits for using the telegram bot. How it goes in my head. We take a simple, serverless key-value database, for example, https://github.com/boltdb/bolt . Unfortunately, I do not know how it will show itself in terms of performance. Since the database bolt is essentially a file that is locked when writing. Asynchronously it will not turn out to have access. If 15 people fall on the bot at the same time, then the speed will drop noticeably.
To solve my problem, I want to record for each user the number of requests that will be available to him. Well, once a day, update the number of requests for everyone. I just don't know how to do it with the last one. Just in the code to run a separate gorutin for this or somehow in a smart way.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2022-01-21
@deliro

https://github.com/boltdb/bolt . Unfortunately, I do not know how it will show itself in terms of performance.

Enough for you. True, the repo says in English in black "This repository has been archived by the owner. It is now read-only.", so you need to use https://github.com/etcd-io/bbolt
Since the database bolt is essentially files that are locked when writing

I'm probably going to break your whole idea of ​​the world, but any database is files
If 15 people fall on the bot at the same time, then the speed will drop noticeably.

Kek. If a 15 million person falls on the bot, then yes, the speed may drop. But in this case, keeping the bot on the same server is a rather strange idea, in any case, because the channel or requests to a real database with data will go first
To solve my problem, I want to record for each user the number of requests that will be available to him. Well, once a day, update the number of requests for everyone.

Usually people start to understand the topic by studying existing solutions on the topic. You didn’t study mathematics, reinventing numbers, axioms, didn’t come up with theorems - it’s all been there. What is the difference? Google rate limiter, million solutions

M
Max, 2022-01-21
@zenwalker

It's not entirely clear why you need a DB here. Implement a token bucket in memory, destroy it once a day. The goroutine approach will work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question