Skip to content

Commit 795e458

Browse files
authored
Feature/replace lodash.uniq with Array.from + Set (ghostfolio#4387)
* Replace lodash.uniq with Array.from + Set * Update chagnelog
1 parent ddc7989 commit 795e458

File tree

6 files changed

+20
-17
lines changed

6 files changed

+20
-17
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
### Changed
1515

1616
- Improved the symbol validation in the _Yahoo Finance_ service (get asset profiles)
17+
- Refactored `lodash.uniq` with `Array.from(new Set(...))`
1718
- Refreshed the cryptocurrencies list
1819

1920
### Fixed

apps/api/src/app/portfolio/calculator/portfolio-calculator.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import {
4949
min,
5050
subDays
5151
} from 'date-fns';
52-
import { isNumber, sortBy, sum, uniq, uniqBy } from 'lodash';
52+
import { isNumber, sortBy, sum, uniqBy } from 'lodash';
5353

5454
export abstract class PortfolioCalculator {
5555
protected static readonly ENABLE_LOGGING = false;
@@ -222,7 +222,7 @@ export abstract class PortfolioCalculator {
222222

223223
const exchangeRatesByCurrency =
224224
await this.exchangeRateDataService.getExchangeRatesByCurrency({
225-
currencies: uniq(Object.values(currencies)),
225+
currencies: Array.from(new Set(Object.values(currencies))),
226226
endDate: endOfDay(this.endDate),
227227
startDate: this.startDate,
228228
targetCurrency: this.currency

apps/api/src/app/portfolio/portfolio.service.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ import {
8282
parseISO,
8383
set
8484
} from 'date-fns';
85-
import { isEmpty, uniq } from 'lodash';
85+
import { isEmpty } from 'lodash';
8686

8787
import { PortfolioCalculator } from './calculator/portfolio-calculator';
8888
import {
@@ -2032,14 +2032,16 @@ export class PortfolioService {
20322032
where: { id: filters[0].id }
20332033
});
20342034
} else {
2035-
const accountIds = uniq(
2036-
activities
2037-
.filter(({ accountId }) => {
2038-
return accountId;
2039-
})
2040-
.map(({ accountId }) => {
2041-
return accountId;
2042-
})
2035+
const accountIds = Array.from(
2036+
new Set(
2037+
activities
2038+
.filter(({ accountId }) => {
2039+
return accountId;
2040+
})
2041+
.map(({ accountId }) => {
2042+
return accountId;
2043+
})
2044+
)
20432045
);
20442046

20452047
currentAccounts = await this.accountService.accounts({

apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
isToday,
2424
subDays
2525
} from 'date-fns';
26-
import { isNumber, uniq } from 'lodash';
26+
import { isNumber } from 'lodash';
2727
import ms from 'ms';
2828

2929
@Injectable()
@@ -515,7 +515,7 @@ export class ExchangeRateDataService {
515515
}
516516
}
517517

518-
return uniq(currencies).filter(Boolean).sort();
518+
return Array.from(new Set(currencies)).filter(Boolean).sort();
519519
}
520520

521521
private prepareCurrencyPairs(aCurrencies: string[]) {

apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
} from '@angular/forms';
2121
import { MatDialogRef } from '@angular/material/dialog';
2222
import { isISO4217CurrencyCode } from 'class-validator';
23-
import { uniq } from 'lodash';
2423
import { Subject, takeUntil } from 'rxjs';
2524

2625
import { CreateAssetProfileDialogMode } from './interfaces/interfaces';
@@ -87,7 +86,9 @@ export class CreateAssetProfileDialog implements OnInit, OnDestroy {
8786
this.createAssetProfileForm.get('addCurrency').value as string
8887
).toUpperCase();
8988

90-
const currencies = uniq([...this.customCurrencies, currency]).sort();
89+
const currencies = Array.from(
90+
new Set([...this.customCurrencies, currency])
91+
).sort();
9192

9293
this.dataService
9394
.putAdminSetting(PROPERTY_CURRENCIES, {

apps/client/src/app/components/user-account-settings/user-account-settings.component.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { FormBuilder, Validators } from '@angular/forms';
2424
import { MatSlideToggleChange } from '@angular/material/slide-toggle';
2525
import { MatSnackBar } from '@angular/material/snack-bar';
2626
import { format, parseISO } from 'date-fns';
27-
import { uniq } from 'lodash';
2827
import ms from 'ms';
2928
import { EMPTY, Subject, throwError } from 'rxjs';
3029
import { catchError, takeUntil } from 'rxjs/operators';
@@ -108,7 +107,7 @@ export class UserAccountSettingsComponent implements OnDestroy, OnInit {
108107
);
109108

110109
this.locales.push(this.user.settings.locale);
111-
this.locales = uniq(this.locales.sort());
110+
this.locales = Array.from(new Set(this.locales)).sort();
112111

113112
this.changeDetectorRef.markForCheck();
114113
}

0 commit comments

Comments
 (0)