-
Notifications
You must be signed in to change notification settings - Fork 55
Mongo ttl index support #779
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
Draft
ArnabChatterjee20k
wants to merge
6
commits into
3.x
Choose a base branch
from
mongo-ttl
base: 3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5f637cb
feat: add support for TTL indexes in database adapters and validation
ArnabChatterjee20k 321a4c5
refactor: standardize method formatting and improve TTL index validat…
ArnabChatterjee20k 151703f
updated adapters with the support method for the ttl index support
ArnabChatterjee20k cc63ade
fix: update TTL index validation messages and conditions for shared t…
ArnabChatterjee20k ed322e6
typo
ArnabChatterjee20k 8fa2454
added ttl index in the missing index message
ArnabChatterjee20k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -488,7 +488,7 @@ public function createCollection(string $name, array $attributes = [], array $in | |
| $orders = $index->getAttribute('orders'); | ||
|
|
||
| // If sharedTables, always add _tenant as the first key | ||
| if ($this->sharedTables) { | ||
| if ($this->sharedTables && $index->getAttribute('type') !== Database::INDEX_TTL) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make this check an (adapter?) method, |
||
| $key['_tenant'] = $this->getOrder(Database::ORDER_ASC); | ||
| } | ||
|
|
||
|
|
@@ -508,6 +508,9 @@ public function createCollection(string $name, array $attributes = [], array $in | |
| $order = $this->getOrder($this->filter($orders[$j] ?? Database::ORDER_ASC)); | ||
| $unique = true; | ||
| break; | ||
| case Database::INDEX_TTL: | ||
| $order = $this->getOrder($this->filter($orders[$j] ?? Database::ORDER_ASC)); | ||
| break; | ||
| default: | ||
| // index not supported | ||
| return false; | ||
|
|
@@ -526,6 +529,14 @@ public function createCollection(string $name, array $attributes = [], array $in | |
| $newIndexes[$i]['default_language'] = 'none'; | ||
| } | ||
|
|
||
| // Handle TTL indexes | ||
| if ($index->getAttribute('type') === Database::INDEX_TTL) { | ||
| $ttl = $index->getAttribute('ttl', 0); | ||
| if ($ttl > 0) { | ||
| $newIndexes[$i]['expireAfterSeconds'] = $ttl; | ||
| } | ||
| } | ||
|
|
||
| // Add partial filter for indexes to avoid indexing null values | ||
| if (in_array($index->getAttribute('type'), [ | ||
| Database::INDEX_UNIQUE, | ||
|
|
@@ -901,10 +912,11 @@ public function deleteRelationship( | |
| * @param array<string> $orders | ||
| * @param array<string, string> $indexAttributeTypes | ||
| * @param array<string, mixed> $collation | ||
| * @param int $ttl | ||
| * @return bool | ||
| * @throws Exception | ||
| */ | ||
| public function createIndex(string $collection, string $id, string $type, array $attributes, array $lengths, array $orders, array $indexAttributeTypes = [], array $collation = []): bool | ||
| public function createIndex(string $collection, string $id, string $type, array $attributes, array $lengths, array $orders, array $indexAttributeTypes = [], array $collation = [], int $ttl = 0): bool | ||
| { | ||
| $name = $this->getNamespace() . '_' . $this->filter($collection); | ||
| $id = $this->filter($id); | ||
|
|
@@ -913,7 +925,7 @@ public function createIndex(string $collection, string $id, string $type, array | |
| $indexes['name'] = $id; | ||
|
|
||
| // If sharedTables, always add _tenant as the first key | ||
| if ($this->sharedTables) { | ||
| if ($this->sharedTables && $type !== Database::INDEX_TTL) { | ||
| $indexes['key']['_tenant'] = $this->getOrder(Database::ORDER_ASC); | ||
| } | ||
|
|
||
|
|
@@ -933,6 +945,8 @@ public function createIndex(string $collection, string $id, string $type, array | |
| case Database::INDEX_UNIQUE: | ||
| $indexes['unique'] = true; | ||
| break; | ||
| case Database::INDEX_TTL: | ||
| break; | ||
| default: | ||
| return false; | ||
| } | ||
|
|
@@ -961,6 +975,11 @@ public function createIndex(string $collection, string $id, string $type, array | |
| $indexes['default_language'] = 'none'; | ||
| } | ||
|
|
||
| // Handle TTL indexes | ||
| if ($type === Database::INDEX_TTL && $ttl > 0) { | ||
| $indexes['expireAfterSeconds'] = $ttl; | ||
| } | ||
|
|
||
| // Add partial filter for indexes to avoid indexing null values | ||
| if (in_array($type, [Database::INDEX_UNIQUE, Database::INDEX_KEY])) { | ||
| $partialFilter = []; | ||
|
|
@@ -1073,7 +1092,7 @@ public function renameIndex(string $collection, string $old, string $new): bool | |
|
|
||
| try { | ||
| $deletedindex = $this->deleteIndex($collection, $old); | ||
| $createdindex = $this->createIndex($collection, $new, $index['type'], $index['attributes'], $index['lengths'] ?? [], $index['orders'] ?? [], $indexAttributeTypes); | ||
| $createdindex = $this->createIndex($collection, $new, $index['type'], $index['attributes'], $index['lengths'] ?? [], $index['orders'] ?? [], $indexAttributeTypes, [], $index['ttl'] ?? 0); | ||
| } catch (\Exception $e) { | ||
| throw $this->processException($e); | ||
| } | ||
|
|
@@ -3395,4 +3414,9 @@ public function getSupportForTrigramIndex(): bool | |
| { | ||
| return false; | ||
| } | ||
|
|
||
| public function getSupportTTLIndexes(): bool | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make sure method names are always consistent:
getSupportForTTLIndexes