From 6e923b907be9537b8bcbee904d907482c0d8d748 Mon Sep 17 00:00:00 2001 From: Christian Mueller Date: Mon, 31 Mar 2014 11:11:09 +0200 Subject: [PATCH] note expiration added --- LANDING.md | 3 +++ src/notehub/storage.clj | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/LANDING.md b/LANDING.md index 3550440..99c6546 100644 --- a/LANDING.md +++ b/LANDING.md @@ -9,8 +9,11 @@ - **Statistics**: a rudimentary statistics available (date of publishing & view counter). - **Export**: the original markdown content can be displayed in plain text format. - **API**: Integrate the publishing functionality into your editor using the official [NoteHub API](/api). +- **Expiration**: All notes with less than 30 views in 30 days from publishing will expire. + ## Changelog + - March 2014: all notes with __less than 30 views in 30 days from publishing__ will expire now - February 2014: a simple JS-client for API testing [added](/api-test.html). - January 2014: - Mobile friendly styling added. diff --git a/src/notehub/storage.clj b/src/notehub/storage.clj index 779f822..9fa7bf3 100644 --- a/src/notehub/storage.clj +++ b/src/notehub/storage.clj @@ -131,3 +131,16 @@ ; we save all short urls of a note for removal later (redis :sadd (str noteID :urls) url) url)))) + +(defn gc [password] + (when (= password (get-setting :admin-pw)) + (let [N 30 + timestamp (- (get-current-date) (* N 24 60 60 1000)) + all-notes (map first (partition 2 (redis :hgetall :note))) + old-notes (filter #(< (Long/parseLong (redis :hget :published %)) timestamp) all-notes) + unpopular-notes (filter #(< (try (Long/parseLong (redis :hget :views %)) + (catch Exception a 0)) N) old-notes)] + (println "timestamp:" (str (java.util.Date. timestamp))) + (println (count unpopular-notes) "deleted") + (doseq [note-id unpopular-notes] + (delete-note note-id)))))