<commit_before>Template.index.onCreated ->
  timer           = false
  self            = @
  @take           = new ReactiveVar 10
  @latest         = new ReactiveVar Collections.files.collection.find {}, sort: 'meta.created_at': -1
  @filesLength    = new ReactiveVar 0
  @getFilesLenght = ->
    Meteor.clearTimeout timer if timer
    timer = Meteor.setTimeout ->
      Meteor.call 'filesLenght', _app.userOnly.get(), (error, length) ->
        if error
          console.error error
        else
          self.filesLength.set length
        timer = false
        return
      return
    , 512

  observers =
    added: ->
      self.getFilesLenght()
      return
    removed: ->
      self.getFilesLenght()
      return

  @autorun ->
    if _app.userOnly.get() and Meteor.userId()
      cursor = Collections.files.collection.find {userId: Meteor.userId()}, sort: 'meta.created_at': -1
    else
      cursor = Collections.files.collection.find {}, sort: 'meta.created_at': -1

    cursor.observeChanges observers
    self.latest.set cursor
    return

  @autorun ->
    _app.subs.subscribe 'latest', self.take.get(), _app.userOnly.get()
    return
  return

Template.index.onRendered ->
  window.IS_RENDERED = true
  return

Template.index.helpers
  take:        -> Template.instance().take.get()
  latest:      -> Template.instance().latest.get()
  uploads:     -> _app.uploads.get()<commit_msg>kind of latency compensation<commit_after>Template.index.onCreated ->
  timer           = false
  self            = @
  @take           = new ReactiveVar 10
  @latest         = new ReactiveVar Collections.files.collection.find {}, sort: 'meta.created_at': -1
  @filesLength    = new ReactiveVar 0
  @getFilesLenght = ->
    Meteor.clearTimeout timer if timer
    timer = Meteor.setTimeout ->
      Meteor.call 'filesLenght', _app.userOnly.get(), (error, length) ->
        if error
          console.error error
        else
          self.filesLength.set length
        timer = false
        return
      return
    , 512

  observers =
    added: ->
      self.getFilesLenght()
      return
    removed: ->
      self.filesLength.set self.filesLength.get() - 1
      self.getFilesLenght()
      return

  @autorun ->
    if _app.userOnly.get() and Meteor.userId()
      cursor = Collections.files.collection.find {userId: Meteor.userId()}, sort: 'meta.created_at': -1
    else
      cursor = Collections.files.collection.find {}, sort: 'meta.created_at': -1

    cursor.observeChanges observers
    self.latest.set cursor
    return

  @autorun ->
    _app.subs.subscribe 'latest', self.take.get(), _app.userOnly.get()
    return
  return

Template.index.onRendered ->
  window.IS_RENDERED = true
  return

Template.index.helpers
  take:        -> Template.instance().take.get()
  latest:      -> Template.instance().latest.get()
  uploads:     -> _app.uploads.get()
{'fraction_non_alphanumeric': 0.1168468782699686, 'fraction_numerical': 0.006627136379490757, 'mean_word_length': 2.300345224395857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '627962', 'n_tokens_mistral': 905, 'n_tokens_neox': 882, 'n_words': 187}