소스 검색

Preload all existing finance docs on import

Innocenty Enikeew 11 년 전
부모
커밋
9d15a5ea25
1개의 변경된 파일8개의 추가작업 그리고 6개의 파일을 삭제
  1. 8 6
      src/financisto.lisp

+ 8 - 6
src/financisto.lisp

@@ -149,7 +149,9 @@
                                 collect entity)
                              #'<
                              :key #'(lambda (i) (parse-integer (getf i :datetime)))))
-         (balances (make-hash-table :size (hash-table-count (gethash "account" db)))))
+         (balances (make-hash-table :size (hash-table-count (gethash "account" db))))
+         (existing-docs (docs (db.find "events" ($ "type" "finance")
+                                       :limit (floor (* 1.1 (length transactions)))))))
     (format t "Got ~A with ~A transactions~%" filename (length transactions))
     (dolist (entity transactions)
       (destructuring-bind (&key from-account-id from-amount
@@ -160,14 +162,14 @@
         (when (not (string= to-account-id "0"))
           (incf (gethash (parse-integer to-account-id) balances 0) (parse-integer to-amount)))
         (let* ((new-doc (make-finance-doc entity db balances))
-               (existing-doc (first (docs (db.find "events"
-                                                   (kv ($ "type" "finance")
-                                                       ($ "financisto.id" (parse-integer -id)))))))
+               (existing-doc (find (parse-integer -id)
+                                   existing-docs
+                                   :key (lambda (d) (get-element "financisto.id" d))))
                (new-ts (parse-integer datetime)))
           (cl-mongo::kv-container-add
            (kv "loc"
-               (if (and existing-doc (= new-ts (cl-mongo::raw
-                                                (get-element "ts" existing-doc))))
+               (if (and existing-doc
+                        (= new-ts (cl-mongo::raw (get-element "ts" existing-doc))))
                    (get-element "loc" existing-doc)
                    (timeliner.locations:point->doc
                     (timeliner.locations:find-location-at new-ts))))