Skip to content

Refactor: Extract importer file index module#381

Open
atanas-dev wants to merge 1 commit into
arc-1813-refactor-codebase-into-modules-mod-3from
arc-1813-module-4
Open

Refactor: Extract importer file index module#381
atanas-dev wants to merge 1 commit into
arc-1813-refactor-codebase-into-modules-mod-3from
arc-1813-module-4

Conversation

@atanas-dev

Copy link
Copy Markdown
Collaborator

TBD

@atanas-dev atanas-dev self-assigned this Jul 21, 2026
@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Pull pipeline performance — large-directory

Site: large-directory · 2,000+ plus targeted file-transfer scenarios files · 10,000 posts · 25,000 postmeta · PHP 8.5.8

trunk baseline unavailable — showing PR numbers only.

Stage Wall time Resume attempts Status Details
playground-sqlite-db-pull 9.60 s 1 condition=db-pull in PHP.wasm
runtime=php.wasm 8.3
wp_mysql_parser=enabled
mode=lexer
native_lexer=verified
native_token_stream=WP_MySQL_Native_Token_Stream
native_token_count=18
native_parser=selected
playground-sqlite-db-apply 3.67 s 1 condition=db-apply to SQLite in PHP.wasm
runtime=php.wasm 8.3
wp_mysql_parser=enabled
mode=parser
native_lexer=verified
native_token_stream=WP_MySQL_Native_Token_Stream
native_token_count=18
native_parser=verified
native_ast=WP_MySQL_Native_Parser_Node
sqlite_driver_parser=verified
Total 13.27 s

Numbers carry runner noise; treat single-run deltas as directional, not authoritative.

📈 Trunk performance history — commit-by-commit timeline.

@atanas-dev
atanas-dev force-pushed the arc-1813-refactor-codebase-into-modules-mod-3 branch from 9595f63 to 987a75b Compare July 21, 2026 13:39
@atanas-dev
atanas-dev force-pushed the arc-1813-refactor-codebase-into-modules-mod-3 branch from 987a75b to 27c2b08 Compare July 21, 2026 15:52
@atanas-dev
atanas-dev force-pushed the arc-1813-refactor-codebase-into-modules-mod-3 branch 2 times, most recently from d2b5891 to c15b139 Compare July 22, 2026 17:06
@atanas-dev
atanas-dev force-pushed the arc-1813-refactor-codebase-into-modules-mod-3 branch from c15b139 to 493054b Compare July 23, 2026 17:32
use RuntimeException;
use function WordPress\Reprint\Exporter\assert_valid_path;

final class IndexLineParser

@adamziel adamziel Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class seems to exist solely as a namespace for the two methods. It doesn't use any internal state and it cannot be extended. Should we just go with two standalone functions? I'm worried about creating a proliferation of small classes.

Comment on lines +592 to 598
if ($this->index_store === null) {
$this->index_store = new IndexStore(
$this->index_file,
$this->index_updates_file,
[$this, "audit_log"],
);
}

@adamziel adamziel Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this PR, I could read this 12 lines long method and understand everything about it. With this PR, I need to read multiple methods, another class, and mentally keep track of additional mutable state. I'm not convinced this is helpful

}
}
return null;
return $this->index_store()->readIndexLine($handle);

@adamziel adamziel Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-existing methods in this repo already use snake_case. Methods introduced in the new classes use camelCase. Let's stick to snake_case since that's what WordPress does.

return $this->index_store;
}

private function remote_index_prefix_matcher(): IndexPathPrefixMatcher

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we're introducing new code, let's make sure it comes with informative doc blocks that explain in simple terms to a new reader what the code does. It makes navigating the codebase much easier without analyzing all the calls. Unfortunately, I haven't found a good way to get LLMs to consistently do that—they often write trivialities or rewrite the code in plain english. The best prompt I found so far is "document code like Linus Torvalds," but I still often spend time rewriting and expanding these comments to explain the intent, provide code examples etc.

One of the best documented classes I know is WP_HTML_Processor, largely thanks to @dmsnell. I always keep that in mind as an ideal model.

"size" => (int) ($data["size"] ?? 0),
"type" => (string) ($data["type"] ?? "file"),
];
return IndexLineParser::parse($line);

@adamziel adamziel Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also remove the entire private function and just call a global parse_index_line( $line ) directly. That being said, it's a pretty small function. Are we gaining much by removing it one step from the class that also determines the shape of that index? Looking at this a few lines below, I don't think OOP is serving us well here:

$this->index_store()->beginUpdates();
$this->index_updates_file = $this->index_store()->updatesFile();

Perhaps we could extract the entire indexing stage of the pipeline as the sole new class with just one responsibility?

: 256 * 1024 * 1024;

$sorter = new \ExternalMergeSort(
new IndexLinePathKeyExtractor(),

@adamziel adamziel Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto as other comments – we're swapping a tiny inline function for another class living in another file that delegates work into yet another class, I'd say this is adding cognitive effort, not decreasing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants