Skip to content

Commit

Permalink
Make "Steam data last updated" more accurate
Browse files Browse the repository at this point in the history
Delete cached data for steamids that don't have any demos when refreshing steam data.
  • Loading branch information
bugdone committed Mar 17, 2019
1 parent b179eea commit 1855846
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/hsbox/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@
(json/write-str (second steamid-info))]))))
steamids-info)

(defn delete-old-steamids []
(with-db-transaction t-con
(jdbc/execute! t-con ["DELETE FROM steamids WHERE timestamp > 0 AND timestamp < ?" (- (current-timestamp) (* 3600 (+ 24 6)))])))

(defn get-demo-notes [demoid]
(:notes (first (query-db ["SELECT notes FROM demos WHERE rowid=?" demoid]))))

Expand Down
2 changes: 1 addition & 1 deletion src/hsbox/stats.clj
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@
(try
(try
(reset! api-refreshing? true)
(steamapi/get-steamids-info (keys player-demos) :refresh-all? @refresh-all-players?)
(steamapi/get-steamids-info (keys player-demos) :refresh-all? @refresh-all-players? :delete-old? true)
(finally
(reset! refresh-all-players? false)
(reset! api-refreshing? false)))
Expand Down
8 changes: 5 additions & 3 deletions src/hsbox/steamapi.clj
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,18 @@
(filter #(> (:timestamp %) (- (current-timestamp) (* 24 3600 steamids-stale-days))))
(reduce #(assoc % (:steamid %2) %2) {})))

(defn get-steamids-info [steamids & {:keys [refresh-all?] :or {refresh-all? false}}]
(defn get-steamids-info [steamids & {:keys [refresh-all? delete-old?] :or {refresh-all? false delete-old? false}}]
(assert (every? #(= Long %)
(map #(type %) steamids)))
(if (not (str/blank? (get-steam-api-key)))
(let [cached (if refresh-all?
[]
(get-steamids-info-cached steamids))
to-get (clojure.set/difference (set steamids) (set (keys cached)))
_ (if (not (empty? to-get))
(debug "Getting fresh data from the API for" (count to-get) "steamids"))
from-api (apply merge (map get-steamids-info-from-api (partition 100 100 [] to-get)))]
(if (not (empty? to-get))
(debug "Getting fresh data from the API for" (count to-get) "steamids"))
(if (or refresh-all? delete-old?)
(db/delete-old-steamids))
(merge cached from-api))
{}))

0 comments on commit 1855846

Please sign in to comment.