Skip to content

Bunch of changes to databaseinterface.cpp to try to improve readability

Jack Hill requested to merge jackh/elisa:database-readability into master

Reason for the change

I started working on adding support for multi-valued tags (e.g. multiple genres) and found this file to be very difficult to parse. This is mainly due to the sheer size of the file but there were some other readability issues that I have changed.

These changes are made to my preference, so please let me know if you disagree with anything.

Combine database table checks into 1 function

  • Now we just declare the expected table structure at the top of the file

Delete unused enum

  • Wasn't used

DatabaseInterface::checkDatabaseSchema: refactor as pure function

DatabaseInterface::checkTable: refactor as pure function

  • This makes the context that calls these much easier to parse. We no longer have to worry about the internals of this or how it might change the state of the database/class.

DatabaseInterface: Rename query initialization functions

DatabaseInterface: Rename manageNewDatabaseVersion

  • Makes it much easier to understand the intent of these functions

DatabaseInterface: add method currentDatabaseVersion for readability

  • Makes it easier to read the context that calls this function

DatabaseInterface: set latest DB version at top of file next to latest schema

  • Previously we were setting this in two places, now we set it in one. I placed this near the database schema declaration since these two variables are inherently linked.

Move albumInfoIsSame() from DatabaseInterface to TrackDataType

Move isSameTrack from DatabaseInterface to TrackDataType

  • These functions only compare the internals of two TrackDataTypes. This just helps to reduce the line count of the file.

DatabaseInterface: Re-order methods

  • I find it much easier to read code when all the related functions are grouped together.

Test plan

Tests are still passing

Edited by Jack Hill

Merge request reports

Loading