Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Short code generator starts from the beginning after application restart #2

Open
nnovoice opened this issue Mar 21, 2020 · 2 comments
Assignees

Comments

@nnovoice
Copy link
Owner

Short code generator is created as an Iterator that starts from aaaaaaaa and goes on.
It does not remember where it left off on an application restart. Got to fix this.

@raoprasad-zz
Copy link
Collaborator

raoprasad-zz commented Mar 22, 2020

Potential approaches below. Let's review and identify one:

  1. Add an entry for the next indices and length of sequence in DB to restore on restart.
  2. Add a column for time ticks(elapsed since epoc) in the URL table in postgre. On restart, obtain the latest URL inserted based on the time ticks. Identify current indices based on the short url in the record. generate next url based on current short url.

Edit: Looking at "#3", it appears neither of the options will work. Instead we completely randomize the sequence and check against the URL repository to check if the sequence has been consumed.

@nnovoice
Copy link
Owner Author

We need to find a way to return sequences in a random order.
How about pre-generating say 10 million sequences and return them randomly? the next 10 million can be generated when needed and randomize them. we could potentially do this in a separate thread pool.
Need a simple mechanism.

@raoprasad-zz raoprasad-zz self-assigned this Apr 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants