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

Add a function to get the size of a collection/table in bytes. #272

Merged
merged 39 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2711213
fixed stuff
faisalill May 26, 2023
e645817
fixed indentation
faisalill May 29, 2023
32166d1
indentation cleanup
faisalill May 29, 2023
de08dca
fixed indentation
faisalill May 30, 2023
aec995d
fixed indentation for all adapters
faisalill May 30, 2023
c7b797f
Merge branch 'utopia-php:main' into main
faisalill Jun 1, 2023
d66d2f8
fixed mysql test issue
faisalill Jun 3, 2023
6afaf6f
getSizeOfCollection analyzes the table before getting the size
faisalill Jun 9, 2023
540fe3c
added analyzeCollection function
faisalill Jun 12, 2023
a305282
Merge branch 'utopia-php:main' into main
faisalill Jun 12, 2023
a664c6b
called analyzeCollection from getSizeOfCollection
faisalill Jun 12, 2023
7b0a74a
removed Return from comments
faisalill Jun 12, 2023
7419c99
Merge branch 'utopia-php:main' into main
faisalill Jun 18, 2023
2e60d71
remove analyzeCollection and changed query for mariadb and mysql
faisalill Jun 21, 2023
416fa5f
cleaner code
faisalill Jun 21, 2023
b6c4a03
added camel case for index
faisalill Jun 21, 2023
682ca9f
removed analyze for sqlite
faisalill Jun 21, 2023
3dc00b3
cleaner code
faisalill Jun 21, 2023
ecda582
changed mariadb query
faisalill Jun 22, 2023
4a6ce3f
changed query of getSizeOfCollection
faisalill Jun 29, 2023
faab827
fixed lint issues
faisalill Jul 12, 2023
51ffb2c
fixed phpstan issue
faisalill Jul 13, 2023
2761977
removed mytest from composer.json
faisalill Jul 13, 2023
4c13af1
Merge branch 'utopia-php:main' into main
faisalill Jul 18, 2023
af69df4
removed mytest from composer.json
faisalill Jul 18, 2023
ac21574
Add explanation for asserting a constant with size difference
faisalill Jul 18, 2023
7abfde5
Fix lint issue
faisalill Jul 18, 2023
21550ff
Merge branch 'utopia-php:main' into main
faisalill Jul 22, 2023
d12f27b
Made changes as per review
faisalill Jul 26, 2023
9e96dc0
Merge branch 'main' of https://github.com/faisalill/database
faisalill Jul 26, 2023
a0ec416
Apply suggestions from code review
abnegate Jul 26, 2023
ff872db
Make changes as per review
faisalill Jul 27, 2023
06fe605
Add full text test
faisalill Aug 8, 2023
1763e86
Change MongoDB return value
faisalill Aug 10, 2023
1ebd9f2
Remove mytest script from composer.json
faisalill Aug 10, 2023
8484dc8
Use better collection name
faisalill Aug 10, 2023
5048976
Apply suggestions from code review
abnegate Aug 10, 2023
87adb16
Merge branch 'main' into main
abnegate Aug 10, 2023
3b65416
Fix lint
abnegate Aug 10, 2023
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
3 changes: 3 additions & 0 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ public function getSizeOfCollection(string $collection): int
$collectionName = "{$this->getNamespace()}_{$name}";
fogelito marked this conversation as resolved.
Show resolved Hide resolved
$database = $this->getDefaultDatabase();

faisalill marked this conversation as resolved.
Show resolved Hide resolved
$analyzeTable = $this->getPDO()->prepare("ANALYZE TABLE {$database}.{$collectionName}");
faisalill marked this conversation as resolved.
Show resolved Hide resolved
$analyzeTable->execute();

$query = $this->getPDO()->prepare("
SELECT SUM(data_length + index_length) AS total_size
FROM information_schema.TABLES
Expand Down
17 changes: 2 additions & 15 deletions tests/Database/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,6 @@ public function testCreateListExistsDeleteCollection(): void

public function testSizeCollection(): void
{
if(static::getAdapterName() === 'mysql'){
$loopCount = 3000;
}
else{
$loopCount = 20;
}

static::getDatabase()->createCollection('size_test1');
static::getDatabase()->createCollection('size_test2');

Expand All @@ -137,12 +130,10 @@ public function testSizeCollection(): void
static::getDatabase()->createAttribute('size_test2', 'string1', Database::VAR_STRING, 128, true);
static::getDatabase()->createAttribute('size_test2', 'string2', Database::VAR_STRING, 254 + 1, true);
faisalill marked this conversation as resolved.
Show resolved Hide resolved
static::getDatabase()->createAttribute('size_test2', 'string3', Database::VAR_STRING, 254 + 1, true);
static::getDatabase()->createAttribute('size_test2', 'string4', Database::VAR_STRING, 254 + 1, true);
static::getDatabase()->createAttribute('size_test2', 'integer', Database::VAR_INTEGER, 10, true);
static::getDatabase()->createAttribute('size_test2', 'bigint', Database::VAR_INTEGER, 8, true);
static::getDatabase()->createAttribute('size_test2', 'float', Database::VAR_FLOAT, 0, true);
static::getDatabase()->createIndex('size_test2', 'multi_index', Database::INDEX_KEY, ['string1', 'string2', 'string3'], [128, 128, 128]);

$loopCount = 25;

for ($i = 0; $i < $loopCount; $i++) {
static::getDatabase()->createDocument('size_test2', new Document([
'$permissions' => [
Expand All @@ -154,10 +145,6 @@ public function testSizeCollection(): void
'string1' => 'string1' . $i,
'string2' => 'string2' . $i,
'string3' => 'string3' . $i,
'string4' => "string4" . $i,
'integer' => 35635353 + $i,
'bigint' => 3535353 + $i,
'float' => 353.3535 + $i,
]));
}

Expand Down