DanielChang98 / link-shortener

Link shortener built using Rails
0 stars 0 forks source link

Improvements and Questions #1

Open tmlee opened 3 years ago

tmlee commented 3 years ago
  1. https://github.com/DanielChang98/link-shortener/blob/main/app/services/shortener.rb#L18 Knowing how hash function works, if you want to proceed with your approach of generating new codes, is a loop check necessary?

  2. Why pass in a Link object here when it seems like it won't be anything else? https://github.com/DanielChang98/link-shortener/blob/main/app/services/shortener.rb#L6

  3. If we want to add a new feature to track the number of clicks and IP source for when a shortened URL is visited by a suer, how would you implement that? Display the results publicly.

  4. After implementing the above, how can we improve the performance of a link visit while also counting the number of visits?

DanielChang98 commented 3 years ago
  1. The loop can be removed, but the justification was 'just in case'. Although uuids itself are unique, but since only the first 7 characters are extracted, i was not sure what are the chances of a repeated 7-character lookup code (although the probability do be kinda low, now thinking about it). I'll remove it.

  2. I'll remove it and change link.model just to Link.

For 3 and 4, I am aware that this project has not achieve all the requirements stated in the email. I have a rough idea, but I'll solidify and implement it ASAP.

DanielChang98 commented 3 years ago
  1. The new feature has been implemented and the app is deployed here.

Screenshot from 2021-03-31 16-45-10

Implementation Method

  1. Add counter into Link model.
  2. Create new Visitor model with link_id as foreign key. Each Link has many Visitor.
  3. Each shortened link visit will increment counter and create new Visitor entry.
  4. Display all the shortened links at home page in a table with attributes: original_url, shortened_url and counter.
  5. Clicking table row ID will redirect user to shortened link statistics, where ip is/are shown.

Even Better If

  1. Display only the shortened links created by the user in table
  2. Table is populated with new row when new link is shortened.
  3. Add pagination to table
  4. Better design