@@ -16,20 +16,18 @@ final class MongoLock extends Lock
16
16
/**
17
17
* Create a new lock instance.
18
18
*
19
- * @param Collection $collection The MongoDB collection
20
- * @param string $name Name of the lock
21
- * @param int $seconds Time-to-live of the lock in seconds
22
- * @param string|null $owner A unique string that identifies the owner. Random if not set
23
- * @param array $lottery The prune probability odds
24
- * @param int $defaultTimeoutInSeconds The default number of seconds that a lock should be held
19
+ * @param Collection $collection The MongoDB collection
20
+ * @param string $name Name of the lock
21
+ * @param int $seconds Time-to-live of the lock in seconds
22
+ * @param string|null $owner A unique string that identifies the owner. Random if not set
23
+ * @param array $lottery Probability [chance, total] of pruning expired cache items. Set to [0] to disable
25
24
*/
26
25
public function __construct (
27
26
private readonly Collection $ collection ,
28
27
string $ name ,
29
28
int $ seconds ,
30
29
?string $ owner = null ,
31
30
private readonly array $ lottery = [2 , 100 ],
32
- private readonly int $ defaultTimeoutInSeconds = 86400 ,
33
31
) {
34
32
parent ::__construct ($ name , $ seconds , $ owner );
35
33
}
@@ -62,7 +60,7 @@ public function acquire(): bool
62
60
'expiration ' => [
63
61
'$cond ' => [
64
62
'if ' => $ isExpiredOrAlreadyOwned ,
65
- 'then ' => $ this ->expiresAt ( ),
63
+ 'then ' => $ this ->getUTCDateTime ( $ this -> seconds ),
66
64
'else ' => '$expiration ' ,
67
65
],
68
66
],
@@ -135,17 +133,7 @@ protected function getCurrentOwner(): ?string
135
133
)['owner ' ] ?? null ;
136
134
}
137
135
138
- /**
139
- * Get the UNIX timestamp indicating when the lock should expire.
140
- */
141
- private function expiresAt (): UTCDateTime
142
- {
143
- $ lockTimeout = $ this ->seconds > 0 ? $ this ->seconds : $ this ->defaultTimeoutInSeconds ;
144
-
145
- return $ this ->getUTCDateTime ($ lockTimeout );
146
- }
147
-
148
- protected function getUTCDateTime (int $ additionalSeconds = 0 ): UTCDateTime
136
+ private function getUTCDateTime (int $ additionalSeconds = 0 ): UTCDateTime
149
137
{
150
138
return new UTCDateTime (Carbon::now ()->addSeconds ($ additionalSeconds ));
151
139
}
0 commit comments