<commit_before>debug = require('debug') 'gc:geologs'
upsert = require './upsert'
refreshView = require './refresh-view'
Promise = require 'bluebird'

module.exports = (db) ->
    _refresh = refreshView db, 'logsRel', 5000, debug

    upsert: (data) ->
        debug "upsert #{data.Code?.toLowerCase()}"
        upsert db, 'logs', data
        _refresh()

    latest: Promise.coroutine (username) ->
        debug "latest #{username}"
        [client, done] = yield db.connect()
        try
            sql = db.select()
                .from 'logsRel'
                .field 'id'
                .order 'createdate', false
                .limit 1
            sql = sql.where 'lower(username) = ?', username.trim().toLowerCase() if username?
            sql = sql.toString()
<commit_msg>No need to refresh logsrel<commit_after>debug = require('debug') 'gc:geologs'
upsert = require './upsert'
Promise = require 'bluebird'

module.exports = (db) ->
    upsert: (data) ->
        debug "upsert #{data.Code?.toLowerCase()}"
        upsert db, 'logs', data

    latest: Promise.coroutine (username) ->
        debug "latest #{username}"
        [client, done] = yield db.connect()
        try
            sql = db.select()
                .from 'logsRel'
                .field 'id'
                .order 'createdate', false
                .limit 1
            sql = sql.where 'lower(username) = ?', username.trim().toLowerCase() if username?
            sql = sql.toString()

{'fraction_non_alphanumeric': 0.14111261872455902, 'fraction_numerical': 0.004070556309362279, 'mean_word_length': 1.9678068410462777, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2068886', 'n_tokens_mistral': 428, 'n_tokens_neox': 420, 'n_words': 114}