<commit_before>(in-package :turtl)

(defafun get-board-size (future) (board-id)
  "Grab the size of a board, in bytes (notes: note body + note file size)."
  (alet* ((sock (db-sock))
          (query (r:r
                   (:reduce
                     (:map
                       (:get-all
                         (:table "notes")
                         board-id
                         :index (db-index "notes" "board_id"))
                       (:js "(function(note) { return ((note.body && note.body.length) || 0) + ((note.file && note.file.size) || 0); })"))
                     (r:fn (a b) (:+ a b))
                     :base 0)))
          (size (r:run sock query)))
    (r:disconnect sock)
    (finish future (round size))))

(defafun get-profile-size (future) (user-id)
  "Grab a user's profile size (size of owned boards + shared boards)."
  (alet* ((board-ids (get-all-user-board-ids user-id :shared t))
          (board-ids (coerce board-ids 'list))
          (size 0))
    (wait-for (adolist (board-id board-ids future2)<commit_msg>backend profile size calculator now only takes personal boards into account (vs boards shared with you)<commit_after>(in-package :turtl)

(defafun get-board-size (future) (board-id)
  "Grab the size of a board, in bytes (notes: note body + note file size)."
  (alet* ((sock (db-sock))
          (query (r:r
                   (:reduce
                     (:map
                       (:get-all
                         (:table "notes")
                         board-id
                         :index (db-index "notes" "board_id"))
                       (:js "(function(note) { return ((note.body && note.body.length) || 0) + ((note.file && note.file.size) || 0); })"))
                     (r:fn (a b) (:+ a b))
                     :base 0)))
          (size (r:run sock query)))
    (r:disconnect sock)
    (finish future (round size))))

(defafun get-profile-size (future) (user-id)
  "Grab a user's profile size (only the boards they own)."
  (alet* ((board-ids (get-all-user-board-ids user-id :shared nil))
          (board-ids (coerce board-ids 'list))
          (size 0))
    (wait-for (adolist (board-id board-ids future2)
{'fraction_non_alphanumeric': 0.15219378427787933, 'fraction_numerical': 0.004570383912248629, 'mean_word_length': 1.7091584158415842, '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': '4290553', 'n_tokens_mistral': 701, 'n_tokens_neox': 653, 'n_words': 199}