Load the update information asyncroniously to fix the page load speed

This commit is contained in:
Joas Schilling 2015-06-10 12:01:54 +02:00
parent 4d88302b3a
commit 580155abe7
4 changed files with 30 additions and 12 deletions

View File

@ -797,9 +797,11 @@ class OC_App {
* List all apps, this is used in apps.php * List all apps, this is used in apps.php
* *
* @param bool $onlyLocal * @param bool $onlyLocal
* @param bool $includeUpdateInfo Should we check whether there is an update
* in the app store?
* @return array * @return array
*/ */
public static function listAllApps($onlyLocal = false) { public static function listAllApps($onlyLocal = false, $includeUpdateInfo = true) {
$installedApps = OC_App::getAllApps(); $installedApps = OC_App::getAllApps();
//TODO which apps do we want to blacklist and how do we integrate //TODO which apps do we want to blacklist and how do we integrate
@ -841,7 +843,7 @@ class OC_App {
$info['removable'] = true; $info['removable'] = true;
} }
$info['update'] = OC_Installer::isUpdateAvailable($app); $info['update'] = ($includeUpdateInfo) ? OC_Installer::isUpdateAvailable($app) : null;
$appIcon = self::getAppPath($app) . '/img/' . $app . '.svg'; $appIcon = self::getAppPath($app) . '/img/' . $app . '.svg';
if (file_exists($appIcon)) { if (file_exists($appIcon)) {

View File

@ -147,16 +147,18 @@ class AppSettingsController extends Controller {
* Get all available apps in a category * Get all available apps in a category
* *
* @param int $category * @param int $category
* @param bool $includeUpdateInfo Should we check whether there is an update
* in the app store?
* @return array * @return array
*/ */
public function listApps($category = 0) { public function listApps($category = 0, $includeUpdateInfo = true) {
if(!is_null($this->cache->get('listApps-'.$category))) { if(!is_null($this->cache->get('listApps-'.$category))) {
$apps = $this->cache->get('listApps-'.$category); $apps = $this->cache->get('listApps-'.$category);
} else { } else {
switch ($category) { switch ($category) {
// installed apps // installed apps
case 0: case 0:
$apps = $this->getInstalledApps(); $apps = $this->getInstalledApps($includeUpdateInfo);
usort($apps, function ($a, $b) { usort($apps, function ($a, $b) {
$a = (string)$a['name']; $a = (string)$a['name'];
$b = (string)$b['name']; $b = (string)$b['name'];
@ -168,7 +170,7 @@ class AppSettingsController extends Controller {
break; break;
// not-installed apps // not-installed apps
case 1: case 1:
$apps = \OC_App::listAllApps(true); $apps = \OC_App::listAllApps(true, $includeUpdateInfo);
$apps = array_filter($apps, function ($app) { $apps = array_filter($apps, function ($app) {
return !$app['active']; return !$app['active'];
}); });
@ -189,7 +191,7 @@ class AppSettingsController extends Controller {
$apps = array(); $apps = array();
} else { } else {
// don't list installed apps // don't list installed apps
$installedApps = $this->getInstalledApps(); $installedApps = $this->getInstalledApps(false);
$installedApps = array_map(function ($app) { $installedApps = array_map(function ($app) {
if (isset($app['ocsid'])) { if (isset($app['ocsid'])) {
return $app['ocsid']; return $app['ocsid'];
@ -245,10 +247,12 @@ class AppSettingsController extends Controller {
} }
/** /**
* @param bool $includeUpdateInfo Should we check whether there is an update
* in the app store?
* @return array * @return array
*/ */
private function getInstalledApps() { private function getInstalledApps($includeUpdateInfo = true) {
$apps = \OC_App::listAllApps(true); $apps = \OC_App::listAllApps(true, $includeUpdateInfo);
$apps = array_filter($apps, function ($app) { $apps = array_filter($apps, function ($app) {
return $app['active']; return $app['active'];
}); });

View File

@ -81,7 +81,7 @@ OC.Settings.Apps = OC.Settings.Apps || {
$('#app-category-' + categoryId).addClass('active'); $('#app-category-' + categoryId).addClass('active');
OC.Settings.Apps.State.currentCategory = categoryId; OC.Settings.Apps.State.currentCategory = categoryId;
this._loadCategoryCall = $.ajax(OC.generateUrl('settings/apps/list?category={categoryId}', { this._loadCategoryCall = $.ajax(OC.generateUrl('settings/apps/list?category={categoryId}&includeUpdateInfo=0', {
categoryId: categoryId categoryId: categoryId
}), { }), {
type:'GET', type:'GET',
@ -123,6 +123,20 @@ OC.Settings.Apps = OC.Settings.Apps || {
}, },
complete: function() { complete: function() {
$('#apps-list').removeClass('icon-loading'); $('#apps-list').removeClass('icon-loading');
$.ajax(OC.generateUrl('settings/apps/list?category={categoryId}&includeUpdateInfo=1', {
categoryId: categoryId
}), {
type: 'GET',
success: function (apps) {
_.each(apps.apps, function(app) {
if (app.update) {
var $update = $('#app-' + app.id + ' .update');
$update.removeClass('hidden');
$update.val(t('settings', 'Update to %s').replace(/%s/g, app.update));
}
})
}
});
} }
}); });
}, },

View File

@ -108,9 +108,7 @@ script(
</div> </div>
{{/unless}} {{/unless}}
{{#if update}} <input class="update hidden" type="submit" value="<?php p($l->t('Update to %s', array('{{update}}'))); ?>" data-appid="{{id}}" />
<input class="update" type="submit" value="<?php p($l->t('Update to %s', array('{{update}}'))); ?>" data-appid="{{id}}" />
{{/if}}
{{#if active}} {{#if active}}
<input class="enable" type="submit" data-appid="{{id}}" data-active="true" value="<?php p($l->t("Disable"));?>"/> <input class="enable" type="submit" data-appid="{{id}}" data-active="true" value="<?php p($l->t("Disable"));?>"/>
<input type="checkbox" class="groups-enable" id="groups_enable-{{id}}"/> <input type="checkbox" class="groups-enable" id="groups_enable-{{id}}"/>