Browse Source

Task/improve search log output for unsupported queries (#7480)

* Improve search log output for unsupported queries

* Update changelog
pull/7493/head
Thomas Kaul 1 week ago
committed by GitHub
parent
commit
9b3f7eff5f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      CHANGELOG.md
  2. 13
      apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.service.ts
  3. 7
      apps/api/src/services/data-provider/data-provider.service.ts
  4. 6
      apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts
  5. 2
      libs/common/src/lib/config.ts
  6. 5
      libs/common/src/lib/helper.ts
  7. 9
      libs/ui/src/lib/assistant/assistant.component.ts
  8. 8
      libs/ui/src/lib/symbol-autocomplete/symbol-autocomplete.component.ts

2
CHANGELOG.md

@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added the activity count to the delete menu item of the activities table - Added the activity count to the delete menu item of the activities table
- Added the activity count to the deletion confirmation dialog of the activities table - Added the activity count to the deletion confirmation dialog of the activities table
- Improved the style of the type filter in the activities table component (experimental) - Improved the style of the type filter in the activities table component (experimental)
- Improved the search functionality by trimming the query
- Improved the log output in the search functionality of the _Yahoo Finance_ service for unsupported queries
- Improved the performance of the property service by caching the properties in memory - Improved the performance of the property service by caching the properties in memory
- Improved the language localization for German (`de`) - Improved the language localization for German (`de`)

13
apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.service.ts

@ -17,7 +17,10 @@ import {
DERIVED_CURRENCIES DERIVED_CURRENCIES
} from '@ghostfolio/common/config'; } from '@ghostfolio/common/config';
import { PROPERTY_DATA_SOURCES_GHOSTFOLIO_DATA_PROVIDER_MAX_REQUESTS } from '@ghostfolio/common/config'; import { PROPERTY_DATA_SOURCES_GHOSTFOLIO_DATA_PROVIDER_MAX_REQUESTS } from '@ghostfolio/common/config';
import { getAssetProfileIdentifier } from '@ghostfolio/common/helper'; import {
getAssetProfileIdentifier,
isValidSearchQuery
} from '@ghostfolio/common/helper';
import { import {
DataProviderGhostfolioAssetProfileResponse, DataProviderGhostfolioAssetProfileResponse,
DataProviderHistoricalResponse, DataProviderHistoricalResponse,
@ -344,7 +347,9 @@ export class GhostfolioService {
}: GetSearchParams): Promise<LookupResponse> { }: GetSearchParams): Promise<LookupResponse> {
const results: LookupResponse = { items: [] }; const results: LookupResponse = { items: [] };
if (!query) { query = query?.trim();
if (!isValidSearchQuery(query)) {
return results; return results;
} }
@ -352,10 +357,6 @@ export class GhostfolioService {
let lookupItems: LookupItem[] = []; let lookupItems: LookupItem[] = [];
const promises: Promise<{ items: LookupItem[] }>[] = []; const promises: Promise<{ items: LookupItem[] }>[] = [];
if (query?.length < 2) {
return { items: lookupItems };
}
for (const dataProviderService of this.getDataProviderServices()) { for (const dataProviderService of this.getDataProviderServices()) {
promises.push( promises.push(
dataProviderService.search({ dataProviderService.search({

7
apps/api/src/services/data-provider/data-provider.service.ts

@ -20,7 +20,8 @@ import {
getCurrencyFromSymbol, getCurrencyFromSymbol,
getStartOfUtcDate, getStartOfUtcDate,
isCurrency, isCurrency,
isDerivedCurrency isDerivedCurrency,
isValidSearchQuery
} from '@ghostfolio/common/helper'; } from '@ghostfolio/common/helper';
import { import {
AssetProfileIdentifier, AssetProfileIdentifier,
@ -838,7 +839,9 @@ export class DataProviderService implements OnModuleInit {
let lookupItems: LookupItem[] = []; let lookupItems: LookupItem[] = [];
const promises: Promise<LookupResponse>[] = []; const promises: Promise<LookupResponse>[] = [];
if (query?.length < 2) { query = query?.trim();
if (!isValidSearchQuery(query)) {
return { items: lookupItems }; return { items: lookupItems };
} }

6
apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts

@ -330,7 +330,11 @@ export class YahooFinanceService implements DataProviderInterface {
}); });
} }
} catch (error) { } catch (error) {
this.logger.error(error); if (error?.name === 'BadRequestError') {
this.logger.warn(`Could not search for "${query}": ${error.message}`);
} else {
this.logger.error(error);
}
} }
return { items }; return { items };

2
libs/common/src/lib/config.ts

@ -288,6 +288,8 @@ export const REPLACE_NAME_PARTS = [
'Xtrackers (IE) Plc -' 'Xtrackers (IE) Plc -'
]; ];
export const SEARCH_QUERY_MINIMUM_LENGTH = 2;
export const SECTORS = [ export const SECTORS = [
'Basic Materials', 'Basic Materials',
'Communication Services', 'Communication Services',

5
libs/common/src/lib/helper.ts

@ -41,6 +41,7 @@ import {
DERIVED_CURRENCIES, DERIVED_CURRENCIES,
ghostfolioFearAndGreedIndexSymbolCryptocurrencies, ghostfolioFearAndGreedIndexSymbolCryptocurrencies,
ghostfolioFearAndGreedIndexSymbolStocks, ghostfolioFearAndGreedIndexSymbolStocks,
SEARCH_QUERY_MINIMUM_LENGTH,
TAG_ID_EXCLUDE_FROM_ANALYSIS TAG_ID_EXCLUDE_FROM_ANALYSIS
} from './config'; } from './config';
import { import {
@ -509,6 +510,10 @@ export function isRootCurrency(aCurrency: string) {
}); });
} }
export function isValidSearchQuery(aQuery: string) {
return aQuery?.trim().length >= SEARCH_QUERY_MINIMUM_LENGTH;
}
export function parseDate(date: string): Date | undefined { export function parseDate(date: string): Date | undefined {
if (!date) { if (!date) {
return undefined; return undefined;

9
libs/ui/src/lib/assistant/assistant.component.ts

@ -202,6 +202,11 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
this.searchFormControl.valueChanges this.searchFormControl.valueChanges
.pipe( .pipe(
map((searchTerm) => { map((searchTerm) => {
return searchTerm?.trim();
}),
debounceTime(300),
distinctUntilChanged(),
tap(() => {
this.isLoading = { this.isLoading = {
accounts: true, accounts: true,
assetProfiles: true, assetProfiles: true,
@ -216,11 +221,7 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
}; };
this.changeDetectorRef.markForCheck(); this.changeDetectorRef.markForCheck();
return searchTerm?.trim();
}), }),
debounceTime(300),
distinctUntilChanged(),
switchMap((searchTerm) => { switchMap((searchTerm) => {
const results = { const results = {
accounts: [], accounts: [],

8
libs/ui/src/lib/symbol-autocomplete/symbol-autocomplete.component.ts

@ -41,6 +41,7 @@ import {
debounceTime, debounceTime,
distinctUntilChanged, distinctUntilChanged,
filter, filter,
map,
switchMap switchMap
} from 'rxjs/operators'; } from 'rxjs/operators';
@ -128,6 +129,9 @@ export class GfSymbolAutocompleteComponent
this.control.valueChanges this.control.valueChanges
.pipe( .pipe(
map((query) => {
return isString(query) ? query.trim() : query;
}),
filter((query) => { filter((query) => {
if (query?.length === 0) { if (query?.length === 0) {
this.showDefaultOptions(); this.showDefaultOptions();
@ -137,13 +141,13 @@ export class GfSymbolAutocompleteComponent
return isString(query); return isString(query);
}), }),
debounceTime(400),
distinctUntilChanged(),
tap(() => { tap(() => {
this.isLoading = true; this.isLoading = true;
this.changeDetectorRef.markForCheck(); this.changeDetectorRef.markForCheck();
}), }),
debounceTime(400),
distinctUntilChanged(),
takeUntilDestroyed(this.destroyRef), takeUntilDestroyed(this.destroyRef),
switchMap((query: string) => { switchMap((query: string) => {
return this.dataService.fetchSymbols({ return this.dataService.fetchSymbols({

Loading…
Cancel
Save