Skip to content

Commit 3d87446

Browse files
authored
PS-914_indexer-crash (#625)
* fix old record (add stories[]) only if importStories=false
1 parent bf74909 commit 3d87446

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

databox/indexer/src/handlers/phraseanet/indexer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ export const phraseanetIndexer: IndexIterator<PhraseanetConfig> =
297297
searchParams,
298298
0, // offset
299299
PAGESIZE,
300-
query
300+
query,
301+
dm.importStories ?? false
301302
);
302303
for (const record of records) {
303304
logger.info(

databox/indexer/src/handlers/phraseanet/phraseanetClient.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,16 @@ export default class PhraseanetClient {
107107
params: Record<string, any>,
108108
offset: number = 0,
109109
limit: number = 50,
110-
searchQuery: string
110+
searchQuery: string,
111+
importStories: boolean
111112
): Promise<CPhraseanetRecord[]> {
112113
return this.search(
113114
params,
114115
offset,
115116
PhraseanetSearchType.Record,
116117
searchQuery,
117-
limit
118+
limit,
119+
importStories
118120
) as unknown as Promise<CPhraseanetRecord[]>;
119121
}
120122

@@ -129,7 +131,8 @@ export default class PhraseanetClient {
129131
offset,
130132
PhraseanetSearchType.Story,
131133
searchQuery,
132-
limit
134+
limit,
135+
true
133136
) as unknown as Promise<CPhraseanetStory[]>;
134137
}
135138

@@ -138,7 +141,8 @@ export default class PhraseanetClient {
138141
offset: number = 0,
139142
searchType: PhraseanetSearchType,
140143
searchQuery: string,
141-
limit: number = 100
144+
limit: number = 100,
145+
importStories: boolean
142146
): Promise<(CPhraseanetRecord | CPhraseanetStory)[]> {
143147
let last_error: any = null;
144148
for (let ttry = 1; ttry <= 3; ttry++) {
@@ -168,6 +172,17 @@ export default class PhraseanetClient {
168172
if (searchType === PhraseanetSearchType.Record) {
169173
res.data.response.results.records.map(
170174
(r: PhraseanetRecord) => {
175+
if (r.stories === undefined) {
176+
if (importStories) {
177+
ttry = 3; // deadly error, no need to retry
178+
throw new Error(
179+
'Phraseanet is not up-to-date : importStories requires https://github.com/alchemy-fr/Phraseanet/pull/4602'
180+
);
181+
} else {
182+
// be nice: fix old phraseanet versions
183+
r.stories = [];
184+
}
185+
}
171186
recs.push(new CPhraseanetRecord(r, this));
172187
}
173188
);

0 commit comments

Comments
 (0)