SCE-Development/cleezy

Add "used" column to Urls table

Closed this issue · 0 comments

Inside of the below create table query, lets add a new column that tracks how many times a url was used

create_table_query = """

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:
  1. takes an alias as a parameter and an optional second parameter called count, defaults to 1
  2. increments the alias's used column by the count value
  • call this function right before we return the url in the below file
    return RedirectResponse(url_output)
  • 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