Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make lock expire timer configurable #17

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions aftman.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file lists tools managed by Aftman, a cross-platform toolchain manager.
# For more information, see https://github.com/LPGhatguy/aftman

# To add a new tool, add an entry to this table.
[tools]
wally = "UpliftGames/[email protected]"
# rojo = "rojo-rbx/[email protected]"
12 changes: 9 additions & 3 deletions src/Collection.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
local HttpService = game:GetService("HttpService")
local RunService = game:GetService("RunService")

local Compression = require(script.Parent.Compression)
local Document = require(script.Parent.Document)
local freezeDeep = require(script.Parent.freezeDeep)
local Migration = require(script.Parent.Migration)
local Promise = require(script.Parent.Parent.Promise)

local LOCK_EXPIRE = 30 * 60
local DEFAULT_LOCK_EXPIRE = 30 * 60

--[=[
Collections are analagous to [GlobalDataStore].
Expand All @@ -22,6 +23,8 @@ function Collection.new(name, options, data, autoSave, config)
freezeDeep(options.defaultData)

options.migrations = options.migrations or {}
options.lockExpireTime = options.lockExpireTime or DEFAULT_LOCK_EXPIRE
options.disableLockInStudio = if options.disableLockInStudio ~= nil then options.disableLockInStudio else false

return setmetatable({
dataStore = config:get("dataStoreService"):GetDataStore(name),
Expand Down Expand Up @@ -64,9 +67,12 @@ function Collection:load(key, defaultUserIds)
return "fail", "Saved migration version ahead of latest version"
end

local lockDisabled = if self.options.disableLockInStudio then RunService:IsStudio() else false

if
value.lockId ~= nil
and (DateTime.now().UnixTimestampMillis - keyInfo.UpdatedTime) / 1000 < LOCK_EXPIRE
not lockDisabled
and value.lockId ~= nil
and (DateTime.now().UnixTimestampMillis - keyInfo.UpdatedTime) / 1000 < self.options.lockExpireTime
then
return "retry", "Could not acquire lock"
end
Expand Down
4 changes: 2 additions & 2 deletions wally.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nezuo/lapis"
version = "0.2.6"
name = "davidnurkkala/lapis"
version = "0.2.7"
registry = "https://github.com/UpliftGames/wally-index"
exclude = ["**"]
include = ["src", "src/*", "default.project.json", "wally.toml", "LICENSE"]
Expand Down