Skip to content
This repository has been archived by the owner on Nov 14, 2018. It is now read-only.

Commit

Permalink
Handles userId as case insensitive, fixes #7.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ted committed Jul 24, 2017
1 parent 2ae0977 commit 8825358
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
15 changes: 9 additions & 6 deletions src/fr/tedoldi/lichess/game/retriever/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

[environ.core :as env]

[clojure.string :as str]
[clojure.tools.cli :as cli]
[clojure.term.colors :as color])
(:gen-class))
Expand Down Expand Up @@ -56,12 +57,14 @@
["-h" "--help" "Print this help"]])

(defn run [options]
(->> [:quiet :url :casual :variant :output
:speed :store :no-sync :username
:refresh-all :user-agent
:with-times :color :template-pgn :template-move-pair]
(select-keys options)
core/export!))
(-> options
(select-keys
[:quiet :url :casual :variant :output
:speed :store :no-sync :username
:refresh-all :user-agent
:with-times :color :template-pgn :template-move-pair])
(update :username str/lower-case)
core/export!))

(defn -main [& args]
(try
Expand Down
22 changes: 16 additions & 6 deletions src/fr/tedoldi/lichess/game/retriever/orientdb.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
[clj-time.coerce :as coerce]
[clj-time.core :as t]
clojure.data
[clojure.string :as str]
[clojure.data.json :as json])
(:import (java.io PrintWriter)

Expand Down Expand Up @@ -262,7 +263,6 @@
"dummy"
{:username "dummy"})
(-execute db "CREATE INDEX user._id ON user (_id) UNIQUE")
(-execute db "CREATE INDEX user.username ON user (username) UNIQUE")

(-execute db "CREATE CLASS game")
(-execute db "CREATE PROPERTY game._id STRING")
Expand All @@ -273,7 +273,15 @@
"dummy"
{:username "dummy"})
(-execute db "CREATE INDEX game._id ON game (_id) UNIQUE")
(-execute db "CREATE INDEX game.username ON game (username) UNIQUE")

(finally
(.close db)))))

(defn- -update-db [Dal]
(let [db (pool->db (:config Dal))]
(try
(-execute db "DROP INDEX user.username ON user (_id) UNIQUE")
(-execute db "DROP INDEX game.username ON game (_id) UNIQUE")

(finally
(.close db)))))
Expand Down Expand Up @@ -329,7 +337,7 @@
(let [page-size 100
query (OSQLSynchQuery. (str "SELECT FROM game"
" WHERE "
" userId = ?"
" userId.toLowerCase() = ?"
" AND @rid > " lower-rid
" LIMIT " page-size)
page-size)
Expand All @@ -340,7 +348,7 @@
(-> db
.activateOnCurrentThread

(.query ^OSQLSynchQuery query (to-array [username]))))]
(.query ^OSQLSynchQuery query (to-array [(str/lower-case username)]))))]
(when items
(cons items
(-username->games-paginated
Expand Down Expand Up @@ -411,6 +419,8 @@
(.create (ODatabaseDocumentTx. store))
(initialize-blank-db this))))

(-update-db this)

this)

(find-all [this collection request]
Expand Down Expand Up @@ -566,7 +576,7 @@
[this username]

(let [query (OSQLSynchQuery. (str "SELECT FROM game"
" WHERE userId = ?"
" WHERE userId.toLowerCase() = ?"
" ORDER BY createdAt DESC"
" LIMIT " 1)
1)
Expand All @@ -575,7 +585,7 @@
(-> db
.activateOnCurrentThread

(.query ^OSQLSynchQuery query (to-array [username]))
(.query ^OSQLSynchQuery query (to-array [(str/lower-case username)]))
seq
first
(#(when %
Expand Down

0 comments on commit 8825358

Please sign in to comment.