<commit_before>
module PerfectQueue


class RDBBackend < Backend
  def initialize(uri, table)
    require 'sequel'
    @uri = uri
    @table = table
    @db = Sequel.connect(@uri)
    #init_db(@uri.split('//',2)[0])
    connect {
      # connection test
    }
    @sql = <<SQL
SELECT id, timeout, data, created_at, resource
FROM `#{@table}`
LEFT JOIN (
  SELECT resource AS res,
         CASE WHEN resource IS NULL THEN 0 ELSE COUNT(1) END AS running
  FROM `#{@table}`
  WHERE timeout > ? AND created_at IS NOT NULL
  GROUP BY resource
) AS T ON resource = res
WHERE timeout <= ? AND (running IS NULL OR running < #{MAX_RESOURCE})
ORDER BY timeout ASC LIMIT #{MAX_SELECT_ROW}
SQL<commit_msg>rdb: removed ORDER BY to improve performance<commit_after>
module PerfectQueue


class RDBBackend < Backend
  def initialize(uri, table)
    require 'sequel'
    @uri = uri
    @table = table
    @db = Sequel.connect(@uri)
    #init_db(@uri.split('//',2)[0])
    connect {
      # connection test
    }
    @sql = <<SQL
SELECT id, timeout, data, created_at, resource
FROM `#{@table}`
LEFT JOIN (
  SELECT resource AS res,
         CASE WHEN resource IS NULL THEN 0 ELSE COUNT(1) END AS running
  FROM `#{@table}`
  WHERE timeout > ? AND created_at IS NOT NULL
  GROUP BY resource
) AS T ON resource = res
WHERE timeout <= ? AND (running IS NULL OR running < #{MAX_RESOURCE})
LIMIT #{MAX_SELECT_ROW}
SQL
{'fraction_non_alphanumeric': 0.10975609756097561, 'fraction_numerical': 0.005738880918220947, 'mean_word_length': 3.318885448916409, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '795074', 'n_tokens_mistral': 457, 'n_tokens_neox': 442, 'n_words': 165}