Skip to content

Commit 54eb623

Browse files
committed
refactor: addressed reviewed changes
1 parent cd60d99 commit 54eb623

File tree

2 files changed

+9
-29
lines changed

2 files changed

+9
-29
lines changed

packages/node-core/src/indexer/dynamic-ds.service.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ export class DynamicDsService<DS extends BaseDataSource = BaseDataSource, P exte
128128
* @returns DatasourceParams if found, undefined otherwise
129129
*/
130130
getDatasourceParamByIndex(index: number): DatasourceParams | undefined {
131-
if (!this._datasourceParams || index < 0 || index >= this._datasourceParams.length) {
132-
return undefined;
133-
}
134-
return this._datasourceParams[index];
131+
return this._datasourceParams?.[index];
135132
}
136133

137134
async destroyDynamicDatasource(
@@ -144,16 +141,16 @@ export class DynamicDsService<DS extends BaseDataSource = BaseDataSource, P exte
144141
throw new Error('DynamicDsService has not been initialized');
145142
}
146143

147-
// Validate the global index is within bounds
148-
if (index < 0 || index >= this._datasourceParams.length) {
144+
// Get the datasource at the global index
145+
const dsParam = this._datasourceParams[index];
146+
147+
// Validate datasource exists
148+
if (!dsParam) {
149149
throw new Error(
150150
`Index ${index} is out of bounds. There are ${this._datasourceParams.length} datasource(s) in total`
151151
);
152152
}
153153

154-
// Get the datasource at the global index
155-
const dsParam = this._datasourceParams[index];
156-
157154
// Validate it matches the template name and is not already destroyed
158155
if (dsParam.templateName !== templateName) {
159156
throw new Error(

packages/node-core/src/indexer/indexer.manager.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,28 +125,11 @@ export abstract class BaseIndexerManager<
125125
vm.freeze(async (templateName: string, index: number) => {
126126
await this.dynamicDsService.destroyDynamicDatasource(templateName, blockHeight, index);
127127

128-
// Remove the destroyed datasource from current processing
129-
// The datasource at the global index now has an endBlock set
130-
const destroyedDsParam = this.dynamicDsService.getDatasourceParamByIndex(index);
131-
132-
if (!destroyedDsParam) {
133-
logger.warn(`Unable to filter destroyed datasource at index ${index} - params not found`);
134-
return;
135-
}
136-
137-
// Filter out the destroyed datasource by matching startBlock and args
128+
// Re-filter datasources to exclude the destroyed one
129+
// The destroyed datasource now has endBlock set, so filterDataSources will exclude it
138130
// Note: Reassigning filteredDataSources is intentional - subsequent handlers
139131
// within the same block will see the updated filtered list
140-
filteredDataSources = filteredDataSources.filter((fds) => {
141-
const fdsStartBlock = (fds as any).startBlock;
142-
// For custom datasources, args are stored in processor.options
143-
// For runtime datasources, they may be stored differently
144-
const fdsArgs = JSON.stringify((fds as any).processor?.options || (fds as any).options || {});
145-
const paramArgs = JSON.stringify(destroyedDsParam.args || {});
146-
147-
// Keep datasource if it doesn't match the destroyed one
148-
return !(fdsStartBlock === destroyedDsParam.startBlock && fdsArgs === paramArgs);
149-
});
132+
filteredDataSources = this.filterDataSources(blockHeight, filteredDataSources);
150133
}, 'destroyDynamicDatasource');
151134

152135
return vm;

0 commit comments

Comments
 (0)