Skip to content
This repository has been archived by the owner on Oct 20, 2021. It is now read-only.

Commit

Permalink
fix(apis): api lists are slow to display
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGeraud committed Jan 5, 2018
1 parent bc9059e commit df2adb8
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"enabled": false
},
"rating": {
"enabled": false
"enabled": true
},
"analytics": {
"enabled": false,
Expand Down
6 changes: 4 additions & 2 deletions src/management/api/apis.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ export class ApisController {
this.isAPIsHome = this.$state.includes('apis');

this.createMode = !Constants.devMode; // && Object.keys($rootScope.graviteeUser).length > 0;

this.reloadSyncState();
let that = this;
$scope.$on("$viewContentLoaded", function() {
that.reloadSyncState();
});

this.selectedApis = [];

Expand Down
6 changes: 4 additions & 2 deletions src/portal/api/apis.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
import {IScope} from 'angular';
import * as _ from 'lodash';
import ApiService from "../../services/api.service";
import ViewService from "../../services/view.service";

export class PortalApisController {
Expand All @@ -31,11 +32,12 @@ export class PortalApisController {
private $state,
private $stateParams,
private Constants,
private ViewService) {
private ViewService: ViewService,
private ApiService: ApiService) {
'ngInject';
this.apis = resolvedApis.data;
this.views = resolvedViews;
this.ratingEnabled = Constants.rating && Constants.rating.enabled;
this.ratingEnabled = this.ApiService.isRatingEnabled();
let that = this;
if($stateParams.view) {
this.selectedView = $stateParams.view;
Expand Down
2 changes: 1 addition & 1 deletion src/portal/api/header/api-header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ApiHeaderComponent: ng.IComponentOptions = {
template: require('./api-header.html'),
controller: function(Constants, ApiService: ApiService, $stateParams, $rootScope) {
'ngInject';
this.ratingEnabled = Constants.rating && Constants.rating.enabled;
this.ratingEnabled = ApiService.isRatingEnabled();

this.getEndpoint = function () {
return Constants.portal.entrypoint + this.api.context_path;
Expand Down
5 changes: 3 additions & 2 deletions src/portal/api/rating/apiRating.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import ApiService from '../../../services/api.service';
import NotificationService from '../../../services/notification.service';
import _ = require('lodash');
import UserService from "../../../services/user.service";

class ApiPortalRatingController {
private api: any;
Expand All @@ -31,10 +32,10 @@ class ApiPortalRatingController {
private $mdDialog,
private $state,
private Constants,
private UserService) {
private UserService: UserService) {
'ngInject';

if (!(Constants.rating && Constants.rating.enabled)) {
if (!this.ApiService.isRatingEnabled()) {
$state.go('portal.home');
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/portal/home/home.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@
* limitations under the License.
*/
import angular = require('angular');
import ApiService from "../../services/api.service";

export class HomeController {
private apis: any[];
private homepage: any;
private ratingEnabled: boolean;

constructor (private resolvedApis, private $state, private resolvedHomepage, private Constants) {
constructor ( private resolvedApis,
private $state,
private resolvedHomepage,
private Constants,
private ApiService: ApiService) {
'ngInject';
this.apis = resolvedApis.data;
this.homepage = resolvedHomepage;
this.$state = $state;
this.ratingEnabled = Constants.rating && Constants.rating.enabled;
this.ratingEnabled = ApiService.isRatingEnabled();
}

querySearch(query) {
Expand Down
7 changes: 5 additions & 2 deletions src/portal/portal.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ function portalRouterConfig($stateProvider: ng.ui.IStateProvider) {
resolve: {
api: ($stateParams: ng.ui.IStateParamsService, ApiService: ApiService) =>
ApiService.get($stateParams['apiId']).then(response => response.data),
apiRatingSummary: ($stateParams: ng.ui.IStateParamsService, ApiService: ApiService) =>
ApiService.getApiRatingSummaryByApi($stateParams['apiId']).then(response => response.data),
apiRatingSummary: ($stateParams: ng.ui.IStateParamsService, ApiService: ApiService, Constants) => {
return ApiService.isRatingEnabled()
? ApiService.getApiRatingSummaryByApi($stateParams['apiId']).then(response => response.data)
: null;
},
resolvedApiPermissions: (ApiService, $stateParams) => ApiService.getPermissions($stateParams.apiId),
onEnter: function (UserService, resolvedApiPermissions) {
if (!UserService.currentUser.userApiPermissions) {
Expand Down
7 changes: 7 additions & 0 deletions src/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ export class LogsQuery {

class ApiService {
private apisURL: string;
private Constants: any;

constructor(private $http, Constants) {
'ngInject';
this.apisURL = `${Constants.baseURL}apis/`;
this.Constants = Constants;
}

get(name) {
Expand Down Expand Up @@ -351,6 +353,11 @@ class ApiService {
/*
* API ratings
*/

isRatingEnabled() {
return this.Constants.rating && this.Constants.rating.enabled;
}

getApiRatings(api, pageNumber) {
return this.$http.get(this.apisURL + api + '/ratings?pageSize=10&pageNumber=' + pageNumber);
}
Expand Down

0 comments on commit df2adb8

Please sign in to comment.