Disabled logging; now compiling with threads:on.
h3rald h3rald@h3rald.com
Sun, 26 Apr 2015 16:30:05 +0200
10 files changed,
67 insertions(+),
43 deletions(-)
M
admin/js/utils.js
→
admin/js/utils.js
@@ -127,7 +127,7 @@ * - offset
* - query */ u.paginator = function(obj) { - var max_page = Math.ceil(obj.total/obj.limit)-1; + var max_page = Math.min(14, Math.ceil(obj.total/obj.limit)-1); var c_page = Math.ceil(obj.offset/obj.limit); var page = function(n, sign, disabled){ var klass;
M
lib/cli.nim
→
lib/cli.nim
@@ -2,8 +2,8 @@ import
parseopt2, parsecfg, streams, - strutils, - logging + #logging, + strutils import types, utils@@ -18,7 +18,7 @@ operation = opRun
directory = "" readonly = false logLevelLabel = "INFO" - logLevel = lvlInfo + #logLevel = lvlInfo mount = false reset = false@@ -90,8 +90,9 @@ of "log", "l":
if val == "": fail(102, "Log level not specified.") try: - logLevelLabel = val.toUpper - logLevel = logging.LevelNames.find(logLevelLabel).Level + discard + #logLevelLabel = val.toUpper + #logLevel = logging.LevelNames.find(logLevelLabel).Level except: fail(103, "Invalid log level '$1'" % val) of "import":@@ -130,7 +131,7 @@ file = key
else: discard -var LS*: LiteStore +var LS* {.threadvar.}: LiteStore LS.port = port LS.address = address@@ -147,6 +148,6 @@ LS.reset = reset
# Initialize loggers -logging.level = logLevel -logging.handlers.add(newConsoleLogger(logLevel, "$date $time - ")) -logging.handlers.add(newFileLogger("litestore.log.txt", fmAppend, logLevel, fmtStr = "$date $time - ")) +#logging.level = logLevel +#logging.handlers.add(newConsoleLogger(logLevel, "$date $time - ")) +#logging.handlers.add(newFileLogger("litestore.log.txt", fmAppend, logLevel, fmtStr = "$date $time - "))
M
lib/core.nim
→
lib/core.nim
@@ -9,7 +9,7 @@ pegs,
strtabs, strutils, base64, - logging, + #logging, math import types,@@ -60,18 +60,18 @@ return store.mount.len > 0
proc begin(store: Datastore) = if not LS_TRANSACTION: - store.db.exec("BEGIN".sql) LS_TRANSACTION = true + store.db.exec("BEGIN".sql) proc commit(store: Datastore) = if LS_TRANSACTION: - store.db.exec("COMMIT".sql) LS_TRANSACTION = false + store.db.exec("COMMIT".sql) proc rollback(store: Datastore) = if LS_TRANSACTION: - store.db.exec("ROLLBACK".sql) LS_TRANSACTION = false + store.db.exec("ROLLBACK".sql) # Manage Tags@@ -183,9 +183,9 @@ if fileExists(filename):
filename.writeFile(rawdata) else: raise newException(EFileNotFound, "File not found: $1" % filename) - return $store.retrieveRawDocument(id) + result = $store.retrieveRawDocument(id) else: - return "" + result = "" if singleOp: store.commit() except:
M
lib/queries.nim
→
lib/queries.nim
@@ -121,7 +121,7 @@ SELECT COUNT(DISTINCT tag_id) FROM tags
""" const SQL_COUNT_DOCUMENTS* = sql""" -SELECT COUNT(id) FROM documents +SELECT COUNT(docid) FROM documents """ const SQL_DELETE_DOCUMENTS_BY_TAG* = sql"""
M
lib/server.nim
→
lib/server.nim
@@ -1,5 +1,16 @@
-import asynchttpserver2, asyncdispatch, times, strutils, pegs, strtabs, cgi, logging -import types, utils, api_v1 +import + asynchttpserver2, + asyncdispatch, + times, + strutils, + pegs, + strtabs, + #logging, + cgi +import + types, + utils, + api_v1 proc getReqInfo(req: Request): string = var url = req.url.path@@ -27,7 +38,7 @@ else:
return resError(Http400, "Bad request - Invalid resource: $1" % info.resource) -proc process(req: Request, LS: LiteStore): Response = +proc process(req: Request, LS: LiteStore): Response {.gcsafe.}= var matches = @["", "", ""] template route(req, peg: expr, op: stmt): stmt {.immediate.}= if req.url.path.find(peg, matches) != -1:@@ -67,7 +78,7 @@ setControlCHook(handleCtrlC)
proc serve*(LS: LiteStore) = var server = newAsyncHttpServer() - proc handleHttpRequest(req: Request): Future[void] {.async.} = + proc handleHttpRequest(req: Request): Future[void] {.async, gcsafe, closure.} = info(getReqInfo(req).replace("$", "$$")) let res = req.process(LS) await req.respond(res.code, res.content, res.headers)
M
lib/types.nim
→
lib/types.nim
@@ -52,24 +52,18 @@ id: string,
version: string ] -let PEG_TAG* = peg""" -^\$? [a-zA-Z0-9_\-?~:.@#^!+]+$ -""" - -let PEG_USER_TAG* = peg""" -^[a-zA-Z0-9_\-?~:.@#^!+]+$ -""" - -let PEG_DEFAULT_URL* = peg""" - ^\/{(docs / info)} (\/ {(.+)} / \/?)$ -""" +var + PEG_TAG* {.threadvar.}: Peg + PEG_USER_TAG* {.threadvar.}: Peg + PEG_DEFAULT_URL* {.threadvar.}: Peg + PEG_URL* {.threadvar.}: Peg -let PEG_URL* = peg""" - ^\/({(v\d+)} \/) {([^\/]+)} (\/ {(.+)} / \/?)$ -""" +PEG_TAG = peg"""^\$? [a-zA-Z0-9_\-?~:.@#^!+]+$""" +PEG_USER_TAG = peg"""^[a-zA-Z0-9_\-?~:.@#^!+]+$""" +PEG_DEFAULT_URL = peg"""^\/{(docs / info)} (\/ {(.+)} / \/?)$""" +PEG_URL = peg"""^\/({(v\d+)} \/) {([^\/]+)} (\/ {(.+)} / \/?)$""" -const - CT_JSON* = {"Content-Type": "application/json"} +const CT_JSON* = {"Content-Type": "application/json"} proc ctHeader*(ct: string): StringTableRef = return {"Content-Type": ct}.newStringTable
M
lib/utils.nim
→
lib/utils.nim
@@ -1,4 +1,4 @@
-import json, db_sqlite, strutils, pegs, asyncdispatch, asynchttpserver2, times, logging, math, sqlite3 +import json, db_sqlite, strutils, pegs, asyncdispatch, asynchttpserver2, times, math, sqlite3, strutils import types, queries, contenttypes proc dbQuote*(s: string): string =@@ -8,8 +8,24 @@ if c == '\'': add(result, "''")
else: add(result, c) add(result, '\'') -proc currentTime*(): string = - return getTime().getGMTime().format("yyyy-MM-dd'T'hh:mm:ss'Z'") +proc currentTime*(plain = false): string = + if plain: + return getTime().getGMTime().format("yyyy-MM-dd' @ 'hh:mm:ss") + else: + return getTime().getGMTime().format("yyyy-MM-dd'T'hh:mm:ss'Z'") + +proc msg(kind, message: string, params: varargs[string, `$`]) = + let s = format(message, params) + echo currentTime(true), " ", kind, ": ", s + +proc info*(message: string, params: varargs[string, `$`]) = + msg(" INFO", message, params) + +proc warn*(message: string, params: varargs[string, `$`]) = + msg("WARNING", message, params) + +proc debug*(message: string, params: varargs[string, `$`]) = + msg(" DEBUG", message, params) proc selectDocumentsByTags(tags: string): string = var select_tagged = "SELECT document_id FROM tags WHERE tag_id = '"
M
litestore.nim
→
litestore.nim
@@ -8,8 +8,8 @@ times,
json, pegs, strtabs, - base64, - logging + #logging, + base64 import lib/types, lib/utils,
M
litestore.nim.cfg
→
litestore.nim.cfg
@@ -1,6 +1,6 @@
#define:release dynlibOverride:sqlite3 -threads:off +threads:on # http://crossgcc.rts-software.org/doku.php?id=compiling_for_win32 i386.windows.gcc.path = "/usr/local/gcc-4.8.0-qt-4.8.4-for-mingw32/win32-gcc/bin"