瀏覽代碼

Migrate from Elastic Search to MondoDB

new-scoring
aeris 2 年之前
父節點
當前提交
ced73e10d2
共有 1 個文件被更改,包括 11 次插入9 次删除
  1. 11
    9
      app/lib/datastore.rb

+ 11
- 9
app/lib/datastore.rb 查看文件

@@ -1,13 +1,12 @@
class Datastore
@@index = Stretcher::Server.new(ENV['ES_URL']).index :cryptcheck
@@index.create unless @@index.exists?
@@client = Mongo::Client.new ENV['MONGO_URL']

def self.host(type, host, port)
key = self.key host, port
result = @@index.type(type).get key
result.date = Time.parse result.date
result
rescue Stretcher::RequestError::NotFound
@@client[type].find(key).first
# result = @@index.type(type).get key
# result.date = Time.parse result.date
# result
end

def self.pending(type, host, port)
@@ -15,13 +14,16 @@ class Datastore
end

def self.post(type, host, port, data)
# entry = self.host type, host, port
# entry.delete if entry
#
key = self.key host, port
@@index.type(type).put key, data
data = data.merge key
@@client[type].update_one key, data, {upsert: true}
end

private
def self.key(host, port)
host = "#{host}:#{port}" if port
host
{ host: host, port: port }
end
end

Loading…
取消
儲存