Skip to content

Code cleanup: unused imports, dead code, and dead OneToMany pushes #211

@sameh-farouk

Description

@sameh-farouk

Context

Follow-up to #208 (bug fixes) and #210 (logic issues). During the same audit, several code quality improvements were identified. None affect runtime behavior — these are cleanup items.

Unused imports

  • I1 nodes.ts:16import { allowedNodeEnvironmentFlags } from "process" — never used
  • I2 tftPrice.ts:1,5Store from @subsquid/typeorm-store and In from typeorm — never used

Unused debug variables

  • I3 nodes.ts:672-673 — Variables h and r in getNodePublicConfig() are assigned but never read (leftover debug code)

Dead functions

  • I5 twins.ts:57-119twinCreateOrUpdateOrDelete() is never called from processor.ts. The processor uses twinStored, twinUpdated, twinDeleted individually instead. The function also contains a dormant bug (L5 from Logic issues in event mapping handlers #210 context: misses accountID update on same-batch create+update), but since it's never called, the bug never fires.
  • I6 contracts.ts:375-405contractBilled() is never called. collectContractBillReports() performs the same work and is the function actually used by the processor.

Duplicated certification parsing

  • I8 7 identical switch blocks parsing certification.__kind (Diy/Certified) across nodes.ts (4 occurrences in nodeUpdated, 1 in nodeCertificationSet) and policies.ts (2 occurrences). Should be extracted to a shared helper function.

Dead OneToMany array pushes

These push to @OneToMany relation arrays on the "one" side, which has no effect in TypeORM — the relationship is owned by the "many" side's @ManyToOne foreign key. The pushes modify in-memory arrays but are never persisted.

  • I9 nodes.ts:340savedNode.interfaces.push(newInterface) in nodeUpdated()
  • I10 nodes.ts:140newNode.interfaces = [] in nodeStored() (initialization for an array that's never used)
  • I11 farms.ts:71newFarm.publicIPs?.push(newIP) in farmStored()
  • I12 farms.ts:189savedFarm.publicIPs.push(newIP) in farmUpdated()

Confirmed by model inspection: Both Node.interfaces and Farm.publicIPs are @OneToMany_ relations. The FK lives on Interfaces.node and PublicIp.farm respectively.


Related: #208 (bug fixes), #210 (logic issues), PR #209

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions