diff --git a/dist/index.php b/dist/index.php index 9d7f453..f7c76c0 100644 --- a/dist/index.php +++ b/dist/index.php @@ -23,7 +23,6 @@ $needs_confirmation = false; try { $links = new Links(".links.db", "links.sql"); list($target, $needs_confirmation) = $links->getTarget($path); - $links->handleVisit($path); } catch (Exception $exception) { $error = true; } @@ -63,7 +62,7 @@ if ($target != null && !$needs_confirmation) {

Internal server error

Something went wrong internally, and you could not be redirected. Please try again later.

Confirm redirect

This URL redirects to .

@@ -107,7 +106,7 @@ if ($target != null && !$needs_confirmation) { $("#header").appendChild(header({title: "fwdkr.co"})); $("#footer").appendChild(footer({ vcsURL: "https://git.fwdekker.com/FWDekker/fwdkr.co/", - version: "v1.3.4" + version: "v1.4.0" })); }); diff --git a/dist/links.php b/dist/links.php index 2d5e1f2..2894e0e 100644 --- a/dist/links.php +++ b/dist/links.php @@ -28,6 +28,8 @@ class Links $this->db = new SQLite3($database, SQLITE3_OPEN_READWRITE); } $this->db->enableExceptions(true); + + $this->deleteExpiredLinks(); } /** @@ -57,15 +59,12 @@ class Links } /** - * Increments the visit counter and visit date of the given path. - * - * @param string $path the path to handle a visit to + * Deletes all expired links. */ - function handleVisit(string $path) - { - $stmt = $this->db->prepare("UPDATE links SET visits = visits + 1, last_visit = CURRENT_TIMESTAMP - WHERE path = :path;"); - $stmt->bindValue(":path", $path); + function deleteExpiredLinks(): void { + $now = date("Y-m-d H:i:s"); + $stmt = $this->db->prepare("DELETE FROM links WHERE expires_at < :now;"); + $stmt->bindValue(":now", $now); $stmt->execute(); } } diff --git a/dist/links.sql b/dist/links.sql index 557f5fb..8943406 100644 --- a/dist/links.sql +++ b/dist/links.sql @@ -5,9 +5,8 @@ create table links constraint links_pk primary key, target text not null, - needs_confirmation boolean default false not null, - visits int default 0 not null, - last_visit text + needs_confirmation boolean default false not null, + expires_at datetime default null ); create unique index links_path_uindex