Use getPeople WikiTree API instead of getAncestors (#262)

The getAncestors API is deprecated
This commit is contained in:
Przemek Więch
2026-03-04 20:10:28 +01:00
parent 4f01ec95c9
commit c5d6a9ef42

View File

@@ -12,8 +12,8 @@ import {
import {StringUtils} from 'turbocommons-ts'; import {StringUtils} from 'turbocommons-ts';
import { import {
clientLogin, clientLogin,
getAncestors as getAncestorsApi,
getLoggedInUserName, getLoggedInUserName,
getPeople,
getRelatives as getRelativesApi, getRelatives as getRelativesApi,
Person, Person,
} from 'wikitree-js'; } from 'wikitree-js';
@@ -67,12 +67,19 @@ async function getAncestors(
key: string, key: string,
handleCors: boolean, handleCors: boolean,
): Promise<Person[]> { ): Promise<Person[]> {
// Limit the number of generations of ancestors.
const ancestorsGenerationLimit = 5;
const cacheKey = `wikitree:ancestors:${key}`; const cacheKey = `wikitree:ancestors:${key}`;
const cachedData = getSessionStorageItem(cacheKey); const cachedData = getSessionStorageItem(cacheKey);
if (cachedData) { if (cachedData) {
return JSON.parse(cachedData); return JSON.parse(cachedData);
} }
const result = await getAncestorsApi(key, {}, getApiOptions(handleCors)); const result = await getPeople(
[key],
{ancestors: ancestorsGenerationLimit},
getApiOptions(handleCors),
);
setSessionStorageItem(cacheKey, JSON.stringify(result)); setSessionStorageItem(cacheKey, JSON.stringify(result));
return result; return result;
} }