/** * @param string $name * @param string|string[] $values A blob string or an array of blob strings. If an array * is used, the first element in the array will be inserted * with the `$name` name. The others will be splitted into chunks. All subtables * within one chunk will be serialized as an array where the index is the * subtableId. */ public function insertBlobRecord($name, $values) { if (is_array($values)) { $clean = array(); if (isset($values[0])) { // we always store the root table in a single blob for fast access $clean[] = array($name, $this->compress($values[0])); unset($values[0]); } if (!empty($values)) { // we move all subtables into chunks $chunk = new Chunk(); $chunks = $chunk->moveArchiveBlobsIntoChunks($name, $values); foreach ($chunks as $index => $subtables) { $clean[] = array($index, $this->compress(serialize($subtables))); } } $this->insertBulkRecords($clean); return; } $values = $this->compress($values); $this->insertRecord($name, $values); }
/** * @dataProvider isRecordNameAChunkDataProvider */ public function test_moveArchiveBlobsIntoChunks_shouldSplitBlobsIntoChunks() { $array = array_fill(0, 245, 'test'); $expected = array($this->recordName . '_chunk_0_99' => array_fill(0, Chunk::NUM_TABLES_IN_CHUNK, 'test'), $this->recordName . '_chunk_100_199' => array_fill(100, Chunk::NUM_TABLES_IN_CHUNK, 'test'), $this->recordName . '_chunk_200_299' => array_fill(200, 45, 'test')); $this->assertSame($expected, $this->chunk->moveArchiveBlobsIntoChunks($this->recordName, $array)); }