Sha256: bb4e2f99800274863c65d015e2c36aa5596d4f92e3991d4fe847bac72bac1324

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

local model       = cmsgpack.unpack(ARGV[1])
local uniques     = cmsgpack.unpack(ARGV[2])
local collections = cmsgpack.unpack(ARGV[3])

local function remove_indices(model)
  local memo = model.key .. ":_indices"
  local existing = redis.call("SMEMBERS", memo)

  for _, key in ipairs(existing) do
    redis.call("SREM", key, model.id)
    redis.call("SREM", memo, key)
  end
end

local function remove_uniques(model, uniques)
  local memo = model.key .. ":_uniques"

  for field, _ in pairs(uniques) do
    local key = model.name .. ":uniques:" .. field

    redis.call("HDEL", key, redis.call("HGET", memo, key))
    redis.call("HDEL", memo, key)
  end
end

local function remove_collections(model, collections)
  for _, collection in ipairs(collections) do
    local key = model.key .. ":" .. collection

    redis.call("DEL", key)
  end
end

local function delete(model)
  local keys = {
    model.key .. ":counters",
    model.key .. ":_indices",
    model.key .. ":_uniques",
    model.key
  }

  redis.call("SREM", model.name .. ":all", model.id)
  redis.call("DEL", unpack(keys))
end

remove_indices(model)
remove_uniques(model, uniques)
remove_collections(model, collections)
delete(model)

return model.id

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ohm-2.0.0.alpha2 lib/ohm/lua/delete.lua
ohm-2.0.0.alpha1 lib/ohm/lua/delete.lua