amitt001 / pygmy

An open-source, feature rich & extensible url-shortener + analytics written in Python :cookie:
https://demo.pygy.co/pygmy
MIT License
703 stars 135 forks source link

Link with an expiry time, shown as expired = False on dashboard even after expiry time #29

Open amitt001 opened 5 years ago

amitt001 commented 5 years ago

The pygmy application offers an option to create links that expire after some specific time. This works by attaching an expiry time(in minutes), which is a positive integer, to the link record in DB.

The expiry time of an URL is calculated by url creation time + expiry time and if it is less than the current time, the short link is considered expired and can't be used anymore. If a user is logged in, the dashboard will show this URL as either expired = True or False, depending on weather url was opened after it's expiry time or not. This is where the bug lies.

The reason why the dashboard doesn't have real-time knowledge about the state of URL is, the expiry value in DB is set if a call comes for URL after it has expired. There is no background job for marking the URL as expired.

How this issue can be fixed? This can be fixed by checking the expiry of URL on the application level when building the response data for the dashboard. URL's can be marked as expired at this point and any subsequent call to dashboard doesn't need to make any more updates.