mirror of
https://github.com/silverstripe/silverstripe-textextraction
synced 2024-10-22 09:06:00 +00:00
Merge pull request #10 from chillu/pulls/truncate-db-cache
Truncate FileContentCache by default to avoid SQL query errors
This commit is contained in:
commit
6c7ffa2c6f
@ -64,6 +64,10 @@ File:
|
||||
```
|
||||
|
||||
By default any extracted content will be cached against the database row.
|
||||
In order to stay within common size constraints for SQL queries required in this operation,
|
||||
the cache sets a maximum character length after which content gets truncated (default: 500000).
|
||||
You can configure this value through `FileTextCache_Database.max_content_length` in your yaml configuration.
|
||||
|
||||
|
||||
Alternatively, extracted content can be cached using SS_Cache to prevent excessive database growth.
|
||||
In order to swap out the cache backend you can use the following yaml configuration.
|
||||
|
@ -6,3 +6,6 @@ Injector:
|
||||
|
||||
SolrCellTextExtractor:
|
||||
# base_url: 'http://localhost:8983/solr/update/extract'
|
||||
|
||||
FileTextCache_Database:
|
||||
max_content_length: 500000
|
@ -19,7 +19,8 @@ interface FileTextCache {
|
||||
}
|
||||
|
||||
/**
|
||||
* Caches the extracted content on the record for the file
|
||||
* Caches the extracted content on the record for the file.
|
||||
* Limits the stored file content by default to avoid hitting query size limits.
|
||||
*/
|
||||
class FileTextCache_Database implements FileTextCache {
|
||||
|
||||
@ -28,7 +29,8 @@ class FileTextCache_Database implements FileTextCache {
|
||||
}
|
||||
|
||||
public function save(File $file, $content) {
|
||||
$file->FileContentCache = $content;
|
||||
$maxLength = Config::inst()->get('FileTextCache_Database', 'max_content_length');
|
||||
$file->FileContentCache = ($maxLength) ? substr($content, 0, $maxLength) : $content;
|
||||
$file->write();
|
||||
}
|
||||
|
||||
|
17
tests/FileTextCacheDatabaseTest.php
Normal file
17
tests/FileTextCacheDatabaseTest.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
class FileTextCacheDatabaseTest extends SapphireTest {
|
||||
|
||||
public function testTruncatesByMaxLength() {
|
||||
Config::nest();
|
||||
|
||||
Config::inst()->update('FileTextCache_Database', 'max_content_length', 5);
|
||||
$cache = new FileTextCache_Database();
|
||||
$file = $this->getMock('File', array('write'));
|
||||
$content = '0123456789';
|
||||
$cache->save($file, $content);
|
||||
$this->assertEquals($cache->load($file), '01234');
|
||||
|
||||
Config::unnest();
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user