Skip to content

Commit

Permalink
improve file system speed #137, prepare index migration #74
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Jun 19, 2018
1 parent f1780be commit 55a76f6
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 5,851 deletions.
65 changes: 41 additions & 24 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions src/apis/StorageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use yii\data\ArrayDataProvider;
use luya\admin\models\StorageImage;
use luya\admin\file\Item;
use luya\helpers\ArrayHelper;

/**
* Filemanager and Storage API.
Expand Down Expand Up @@ -88,7 +89,7 @@ public function actionDataFolders()
*/
public function actionDataFiles($folderId = 0, $page = 0)
{
$perPage = 20;
$perPage = 50;
//$totalCount = (new Query())->where(['folder_id' => $folderId, 'is_hidden' => false, 'is_deleted' => false])->count();
$totalCount = StorageFile::find()->where(['folder_id' => $folderId, 'is_hidden' => false, 'is_deleted' => false])->count();

Expand All @@ -98,16 +99,22 @@ public function actionDataFiles($folderId = 0, $page = 0)
$files = $this->getOrSetHasCache(['storageApiDataFiles', $folderId, $page], function() use ($folderId, $page, $perPage, $tinyCrop, $mediumThumbnail) {
$files = [];
$fileQuery = StorageFile::find()
->where(['folder_id' => $folderId, 'is_hidden' => false, 'is_deleted' => false])->offset($page*$perPage)->limit($perPage)->asArray()->all();
//$fileQuery = (new Query())->where(['folder_id' => $folderId, 'is_hidden' => false, 'is_deleted' => false])->offset($page*$perPage)->limit($perPage)->all();
->where(['folder_id' => $folderId, 'is_hidden' => false, 'is_deleted' => false])
->offset($page*$perPage)
->indexBy(['id'])
->limit($perPage)
->asArray()
->all();

// ass the addImage() method requires the list of images and files in Yi::$app->storage we have to inject, them:
Yii::$app->storage->setFilesArray($fileQuery);
Yii::$app->storage->setImagesArray(StorageImage::find()->where(['in', 'file_id', ArrayHelper::getColumn($fileQuery, 'id')])->asArray()->indexBy(['id'])->all());

foreach ($fileQuery as $fileArray) {

$file = Item::create($fileArray);
$data = $file->toArray(['id', 'folderId', 'name', 'isImage', 'sizeReadable', 'extension', 'uploadTimestamp']);
if ($file->isImage) {
/* TODO: as this will consum the full admin_storage_file and admin_storage_image table */
// add tiny thumbnail
if ($tinyCrop) {
$thumbnail = Yii::$app->storage->addImage($file->id, $tinyCrop['id']);
Expand Down
29 changes: 29 additions & 0 deletions src/migrations/m180619_134519_indexes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use yii\db\Migration;

/**
* Class m180619_134519_indexes
*/
class m180619_134519_indexes extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createIndex('admin_storage_image_index1', 'admin_storage_image', ['file_id']);
$this->createIndex('admin_storage_file_index1', 'admin_storage_file', ['folder_id', 'is_hidden', 'is_deleted', 'name_original']);
$this->createIndex('admin_storage_file_index2', 'admin_storage_file', ['is_deleted', 'id']);
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropIndex('admin_storage_image_index1', 'admin_storage_image');
$this->dropIndex('admin_storage_file_index1', 'admin_storage_file');
$this->dropIndex('admin_storage_file_index2', 'admin_storage_file', ['is_deleted', 'id']);
}
}
2 changes: 1 addition & 1 deletion src/resources/dist/css/admin.css

Large diffs are not rendered by default.

124 changes: 1 addition & 123 deletions src/resources/dist/js/login.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 55a76f6

Please sign in to comment.