Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Index #113

Merged
merged 3 commits into from
Apr 16, 2024
Merged

Refactor Index #113

merged 3 commits into from
Apr 16, 2024

Conversation

haszi
Copy link
Contributor

@haszi haszi commented Mar 28, 2024

This PR is a minimal refactoring of Index to move its dependencies out of the class and inject them through the constructor.

The changes are:

  • move requireIndexing() method out of Index into a global function that receives all its dependencies through parameters
  • add a new IndexRepository class that handles all database access for Index, refactor Index to receive an object of this class as a constructor dependency and to pass raw data to it (i.e. data not containing SQL statements)
  • add basic indexing test
  • fix existing test that uses indexing to use IndexRepository

haszi added 3 commits March 26, 2024 15:57
Move requireIndexing method out of Index.
Pass dependencies to requireIndex as parameters.
Add new IndexRepository class to handle all database access.
Inject IndexRepository as a dependency into the constructor of Index and use that instead of directly accessing the database.
Add basic indexing test.
Fix existing test that uses indexing to use IndexRepository.
@haszi
Copy link
Contributor Author

haszi commented Mar 28, 2024

Possible future improvements:

  • push IndexRepository further up the inheritance tree to Format, this will allow all parts of Phd to use the same indexing database (as opposed to creating new instances in multiple places and sometimes not using the same database that was used for indexing)
  • rewrite SQL in IndexRepository to use prepared statements and to possibly use one large INSERT INTO statement vs individual ones for each of the 29k+ index rows - Won't do this: all database access takes no longer than 2-3 seconds total for the entire rendering process (indexing + one format)
  • remove the global ReaderKeeper (from all classes) and pass the current Reader to Formats as needed - Removed from Index and Generic\XHTML
  • move all index database access from Format to IndexRepository

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

Did a brief review but I can't spot anything majorly wrong.

@Girgias Girgias merged commit 40e35fe into php:master Apr 16, 2024
8 checks passed
@haszi haszi deleted the Refactor-Index branch April 16, 2024 10:48
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