Skip to content

Commit

Permalink
Merge pull request #1072 from rodekruis/feat.brotli
Browse files Browse the repository at this point in the history
Performance
  • Loading branch information
arsforza authored Apr 22, 2022
2 parents 58449f6 + b763d48 commit 0077e84
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 144 deletions.
7 changes: 7 additions & 0 deletions docs/TROUBLESHOOT.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,10 @@ Sometimes there is an issue with installing all packages for ibf-api-service. Yo
- cd /home/ibf-user/IBF-system/services/API-service
- npm install
- docker-compose restart ibf-api-service

### 502 Bad Gateway on API-calls/Swagger UI

Sometimes for unknown reasons the API & Swagger are unavailable, while 'docker-compose logs ibf-api-service' tells you that the API is running correctly.
- On the server run 'docker-compose restart nginx' in this case
- which will usually solve it.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { EventState } from 'src/app/types/event-state';
export class AreasOfFocusSummaryComponent implements OnInit, OnDestroy {
private eapActionSubscription: Subscription;
private placeCodeSubscription: Subscription;
private areasOfFocusSubscription: Subscription;
private initialEventStateSubscription: Subscription;
private manualEventStateSubscription: Subscription;

Expand Down Expand Up @@ -53,7 +52,6 @@ export class AreasOfFocusSummaryComponent implements OnInit, OnDestroy {
ngOnDestroy() {
this.eapActionSubscription.unsubscribe();
this.placeCodeSubscription.unsubscribe();
this.areasOfFocusSubscription.unsubscribe();
this.initialEventStateSubscription.unsubscribe();
this.manualEventStateSubscription.unsubscribe();
}
Expand Down Expand Up @@ -114,9 +112,9 @@ export class AreasOfFocusSummaryComponent implements OnInit, OnDestroy {
};

// Get areas of focus from db
this.areasOfFocusSubscription = this.apiService
.getAreasOfFocus()
.subscribe(onAreasOfFocusChange);
if (triggeredAreas.length) {
this.apiService.getAreasOfFocus().subscribe(onAreasOfFocusChange);
}
}

private onEventStateChange = (eventState: EventState) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export class ChatComponent implements OnInit, OnDestroy {
}

private reloadEapAndTrigger() {
this.eapActionsService.loadAdminAreasAndActions();
this.eapActionsService.getTriggeredAreasApi();
this.eventService.getTrigger();
this.placeCodeService.clearPlaceCode();
}
Expand Down
21 changes: 4 additions & 17 deletions interfaces/IBF-dashboard/src/app/components/map/map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ export class MapComponent implements OnDestroy {

this.initialEventStateSubscription = this.eventService
.getInitialEventStateSubscription()
.subscribe(this.onEventStateChage);
.subscribe(this.onEventStateChange);

this.manualEventStateSubscription = this.eventService
.getManualEventStateSubscription()
.subscribe(this.onEventStateChage);
.subscribe(this.onEventStateChange);

this.timelineStateSubscription = this.timelineService
.getTimelineStateSubscription()
Expand Down Expand Up @@ -202,23 +202,10 @@ export class MapComponent implements OnDestroy {
this.timelineState = timelineState;
};

private onEventStateChage = (eventState: EventState) => {
private onEventStateChange = (eventState: EventState) => {
this.eventState = eventState;

if (this.country && this.disasterType) {
this.apiService
.getRecentDates(
this.country.countryCodeISO3,
this.disasterType.disasterType,
)
.subscribe((date) => {
this.onRecentDates(date);
});
}
};

private onRecentDates = (date) => {
this.lastModelRunDate = date.timestamp || date.date;
this.lastModelRunDate = this.timelineState?.today.toUTC().toString();
};

private onPlaceCodeChange = (): void => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ export class UserStateComponent implements OnInit {
.getDisasterTypeSubscription()
.subscribe(this.onDisasterTypeChange);

this.apiService.getCountries().subscribe((countries) => {
if (countries.length === 1) {
this.onCountryChange(countries[0]);
}
});
if (!this.authService.isLoggedIn()) {
this.apiService.getCountries().subscribe((countries) => {
if (countries.length === 1) {
this.onCountryChange(countries[0]);
}
});
}
}

private onCountryChange = (country: Country) => {
Expand Down
11 changes: 9 additions & 2 deletions interfaces/IBF-dashboard/src/app/services/aggregates.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ export class AggregatesService {
this.eventState &&
this.timelineState &&
this.adminLevel &&
this.triggeredAreas &&
((this.eventState.activeEvent && this.triggeredAreas.length) ||
!this.eventState.activeEvent) &&
this.mapService.checkCountryDisasterTypeMatch(
this.country,
this.disasterType,
Expand Down Expand Up @@ -165,7 +166,13 @@ export class AggregatesService {
};

loadAggregateInformation(): void {
if (this.country && this.disasterType) {
if (
this.country &&
this.disasterType &&
this.timelineState.activeLeadTime &&
this.adminLevel &&
this.eventState
) {
this.apiService
.getAggregatesData(
this.country.countryCodeISO3,
Expand Down
19 changes: 9 additions & 10 deletions interfaces/IBF-dashboard/src/app/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,15 @@ export class ApiService {
}

changePassword(password: string): Observable<any> {
console.log('aaaaaApiService : changePassword()');
this.log('ApiService : changePassword()');

return this.post('user/change-password', {
password,
});
}

getCountries(): Observable<Country[]> {
return this.get('country', false).pipe(
getCountries(countryCodesISO3?: string): Observable<Country[]> {
const path = countryCodesISO3 ? `country/${countryCodesISO3}` : 'country';
return this.get(path, false).pipe(
map((countries) => {
return countries.map((country) => {
country.countryDisasterSettings.map((disaster) => {
Expand Down Expand Up @@ -209,9 +208,9 @@ export class ApiService {
eventName: string,
): Observable<GeoJSON.FeatureCollection> {
return this.get(
`admin-areas/${countryCodeISO3}/${disasterType}/${adminLevel}/${
leadTime ? leadTime : '{leadTime}'
}/${eventName || 'no-name'}`,
`admin-areas/${countryCodeISO3}/${disasterType}/${adminLevel}/${leadTime}/${
eventName || 'no-name'
}`,
false,
);
}
Expand All @@ -224,9 +223,9 @@ export class ApiService {
eventName: string,
): Observable<any> {
return this.get(
`admin-areas/aggregates/${countryCodeISO3}/${disasterType}/${adminLevel}/${
leadTime ? leadTime : '{leadTime}'
}/${eventName || 'no-name'}`,
`admin-areas/aggregates/${countryCodeISO3}/${disasterType}/${adminLevel}/${leadTime}/${
eventName || 'no-name'
}`,
false,
);
}
Expand Down
4 changes: 3 additions & 1 deletion interfaces/IBF-dashboard/src/app/services/country.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export class CountryService {
};

public getCountriesByUser(user: User): void {
this.apiService.getCountries().subscribe(this.onCountriesByUser(user));
this.apiService
.getCountries(user.countries.join(','))
.subscribe(this.onCountriesByUser(user));
}

public getAllCountries(): Observable<Country[]> {
Expand Down
106 changes: 42 additions & 64 deletions interfaces/IBF-dashboard/src/app/services/eap-actions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { EventState } from '../types/event-state';
import { TimelineState } from '../types/timeline-state';
import { AdminLevelService } from './admin-level.service';
import { DisasterTypeService } from './disaster-type.service';
import { EventService, EventSummary } from './event.service';
import { EventService } from './event.service';
import { TimelineService } from './timeline.service';

@Injectable({
Expand All @@ -24,11 +24,10 @@ export class EapActionsService {
public triggeredAreas: any[];
private country: Country;
private disasterType: DisasterType;
public disasterTypeSettings: CountryDisasterSettings;
private disasterTypeSettings: CountryDisasterSettings;
private adminLevel: AdminLevel;
private event: EventSummary;
private eventState: EventState;
public timelineState: TimelineState;
private timelineState: TimelineState;

constructor(
private countryService: CountryService,
Expand Down Expand Up @@ -68,9 +67,43 @@ export class EapActionsService {
this.disasterTypeSettings = this.country?.countryDisasterSettings.find(
(s) => s.disasterType === this.disasterType.disasterType,
);
this.loadAdminAreasAndActions();
};

private onTimelineStateChange = (timelineState: TimelineState) => {
this.timelineState = timelineState;
this.getTriggeredAreasApi();
};

private onEventStatusChange = (eventState: EventState) => {
this.eventState = eventState;
this.getTriggeredAreasApi();
};

private onAdminLevelChange = (adminLevel: AdminLevel) => {
this.adminLevel = adminLevel;
this.getTriggeredAreasApi();
};

public getTriggeredAreasApi() {
if (
this.country &&
this.disasterType &&
this.adminLevel &&
this.timelineState?.activeLeadTime &&
this.eventState
) {
this.apiService
.getTriggeredAreas(
this.country.countryCodeISO3,
this.disasterType.disasterType,
this.adminLevel,
this.timelineState.activeLeadTime,
this.eventState.event?.eventName,
)
.subscribe(this.onTriggeredAreas);
}
}

private onTriggeredAreas = (triggeredAreas) => {
this.triggeredAreas = triggeredAreas;
this.triggeredAreas.sort((a, b) =>
Expand All @@ -92,6 +125,10 @@ export class EapActionsService {
this.triggeredAreaSubject.next(this.triggeredAreas);
};

getTriggeredAreas(): Observable<any[]> {
return this.triggeredAreaSubject.asObservable();
}

private formatDates = (triggeredArea) => {
triggeredArea.startDate = DateTime.fromISO(
triggeredArea.startDate,
Expand Down Expand Up @@ -152,61 +189,6 @@ export class EapActionsService {
return (monthNumber + 12 - droughtForecastMonths[0]) % 12;
};

private onEvent = (events) => {
this.event = events[0];
if (this.event && this.timelineState.activeLeadTime) {
this.getTriggeredAreasApi(
this.timelineState.activeLeadTime,
this.adminLevel || this.disasterTypeSettings.defaultAdminLevel,
);
}
};

private onTimelineStateChange = (timelineState: TimelineState) => {
this.timelineState = timelineState;
if (this.event && this.timelineState.activeLeadTime) {
this.getTriggeredAreasApi(
this.timelineState.activeLeadTime,
this.adminLevel || this.disasterTypeSettings.defaultAdminLevel,
);
}
};

private onAdminLevelChange = (adminLevel: AdminLevel) => {
if (this.event && this.timelineState?.activeLeadTime && adminLevel) {
this.getTriggeredAreasApi(this.timelineState?.activeLeadTime, adminLevel);
}
};

private getTriggeredAreasApi(leadTime: string, adminLevel: AdminLevel) {
if (this.disasterType) {
this.apiService
.getTriggeredAreas(
this.country.countryCodeISO3,
this.disasterType.disasterType,
adminLevel,
leadTime,
this.eventState?.event?.eventName,
)
.subscribe(this.onTriggeredAreas);
}
}

loadAdminAreasAndActions() {
if (this.country && this.disasterType) {
this.apiService
.getEventsSummary(
this.country.countryCodeISO3,
this.disasterType.disasterType,
)
.subscribe(this.onEvent);
}
}

getTriggeredAreas(): Observable<any[]> {
return this.triggeredAreaSubject.asObservable();
}

checkEapAction(
action: string,
status: boolean,
Expand All @@ -222,8 +204,4 @@ export class EapActionsService {
eventName,
);
}

private onEventStatusChange(eventState: EventState) {
this.eventState = eventState;
}
}
3 changes: 2 additions & 1 deletion interfaces/IBF-dashboard/src/app/services/map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ export class MapService {
this.eventState &&
this.timelineState &&
this.adminLevel &&
this.triggeredAreas
((this.eventState.activeEvent && this.triggeredAreas.length) ||
!this.eventState.activeEvent)
) {
this.apiService
.getLayers(this.country.countryCodeISO3, this.disasterType.disasterType)
Expand Down
4 changes: 2 additions & 2 deletions interfaces/IBF-dashboard/src/app/services/timeline.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ export class TimelineService {
};

private onRecentDates = (date) => {
if (date.timestamp) {
this.state.today = DateTime.fromISO(date.timestamp);
if (date.timestamp || date.date) {
this.state.today = DateTime.fromISO(date.timestamp || date.date);
} else {
this.state.today = DateTime.now();
}
Expand Down
Loading

0 comments on commit 0077e84

Please sign in to comment.