<commit_before>(ns rmfu.persistance
  (:require [monger.core :as mg]
            [monger.collection :as mc]
            [monger.conversion :refer [from-db-object]]
            [monger.operators :refer :all]
            [buddy.hashers :as hasher]
    ;; [rmfu.model :as model]
            [rmfu.email :as email]
            [environ.core :refer [env]])
  (:import org.bson.types.ObjectId))

(defonce db-config {:name "rmfu"})

(def conn (atom nil))

(let [uri (System/getenv "MONGO_DB_URL")]
  (if (env :production?)
    (reset! conn (mg/connect-via-uri uri))
    (reset! conn (mg/connect))))

(defonce db (mg/get-db (if (env :production?)
                         (:conn @conn) @conn) (:name db-config)))

(defn find-user-by-email [email]
  (mc/find-one-as-map db "users" {:email email}))

(defn update-verify-email!
  "update :verified? field in doc, but only if :verified? is false"
  [user]
  (let [coll "users"
        oid (:_id user)]
    (when-not (:verified? user)
      (try
        (mc/update-by-id db coll oid {$set {:verified? true}})
        (catch Exception e (str "caught exception: " (.getMessage e)))))))<commit_msg>Get database name optionally from environment variables<commit_after>(ns rmfu.persistance
  (:require [monger.core :as mg]
            [monger.collection :as mc]
            [monger.conversion :refer [from-db-object]]
            [monger.operators :refer :all]
            [buddy.hashers :as hasher]
    ;; [rmfu.model :as model]
            [rmfu.email :as email]
            [environ.core :refer [env]])
  (:import org.bson.types.ObjectId))

(defonce db-config {:name (or (System/getenv "RMFU_DB") "rmfu")})

(def conn (atom nil))

(let [uri (System/getenv "MONGO_DB_URL")]
  (if (env :production?)
    (reset! conn (mg/connect-via-uri uri))
    (reset! conn (mg/connect))))

(defonce db (mg/get-db (if (env :production?)
                         (:conn @conn) @conn) (:name db-config)))

(defn find-user-by-email [email]
  (mc/find-one-as-map db "users" {:email email}))

(defn update-verify-email!
  "update :verified? field in doc, but only if :verified? is false"
  [user]
  (let [coll "users"
        oid (:_id user)]
    (when-not (:verified? user)
      (try
        (mc/update-by-id db coll oid {$set {:verified? true}})
        (catch Exception e (str "caught exception: " (.getMessage e)))))))
{'fraction_non_alphanumeric': 0.16559691912708602, 'fraction_numerical': 0.0, 'mean_word_length': 2.705229793977813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1427771', 'n_tokens_mistral': 832, 'n_tokens_neox': 810, 'n_words': 226}