Add "used" column to Urls table
Closed this issue · 0 comments
evanugarte commented
Inside of the below create table query, lets add a new column that tracks how many times a url was used
cleezy/modules/sqlite_helpers.py
Line 14 in 610bd35
to the query we need to add one line like
used INTEGER DEFAULT 1
for the above syntax on column definitions see https://www.tutlane.com/tutorial/sqlite/sqlite-default-constraint
steps to solve
- add new column in table create syntax
- add a helper function in
sqlite_helpers.py
that:
- takes an alias as a parameter and an optional second parameter called
count
, defaults to 1 - increments the alias's
used
column by thecount
value
- call this function right before we return the url in the below file
Line 89 in 610bd35
- make a table of 1000 urls with a python script and HTTP POSTs to your server running locally. how long does
/find/<alias>
take? check the prometheus metrics - after noting the values in the metrics what if we instead solve the issue with a producer/consumer approach?
producer consumer approach
only start this after all steps above are done
- inside of
/find
, we can push the requested alias to a queue - a separate thread can listen for entries (alias names) in the queue, and one at a time pop the entries and increment each alias using the helper function we defined
- after this approach, how long does
/find/<alias>
take`? what if the table has 10,000 rows? - we will need a migration to move the prod data to have this new column before merging this pr