-
Notifications
You must be signed in to change notification settings - Fork 572
Refactor sqlthread #1760
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 sqlthread #1760
Conversation
14b23b8
to
b072dc7
Compare
b072dc7
to
f63d253
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too big, can't review. Needs to be split. Separate code quality, support functions, and the individual levels.
stdeb.cfg
Outdated
@@ -1,7 +1,7 @@ | |||
[DEFAULT] | |||
Package: pybitmessage | |||
Section: net | |||
Build-Depends: dh-python, libssl-dev, python-all-dev, python-setuptools | |||
Build-Depends: dh-python, libssl-dev, python-all-dev, python-setuptools, python-six |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a separate PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is 16a1177 merged from v0.6.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it fine now?
@@ -29,6 +25,8 @@ | |||
except ImportError: | |||
get_plugin = None | |||
|
|||
# pylint: disable=too-many-branches,too-many-statements | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this a code quality only change? Then it should go into a separate PR.
2d9ad93
to
359553b
Compare
The upgrade design is too complicated. There is no need for a separate function per level. |
ad37a9e
to
0097965
Compare
src/class_sqlThread.py
Outdated
self.upgrade_one_level(l) | ||
self.run_migrations(l) | ||
|
||
def upgrade_schema_data_level(self, level): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```def increment_settings_version``
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/class_sqlThread.py
Outdated
method = getattr(self, method_name, lambda: "Invalid version") | ||
return method() | ||
|
||
def run_migrations(self, file_name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def _upgrade_one_level_sql_statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/class_sqlThread.py
Outdated
self.current_level = None | ||
self.max_level = 11 | ||
|
||
def get_current_level(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def __get_current_settings_version
Maybe this can't be private, that's ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/class_sqlThread.py
Outdated
self.cur.execute(item, parameters) | ||
return int(self.cur.fetchall()[0][0]) | ||
|
||
def upgrade_one_level(self, level): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def _upgrade_one_level_method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/class_sqlThread.py
Outdated
@@ -102,11 +189,20 @@ def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-s | |||
settingsversion = BMConfigParser().getint( | |||
'bitmessagesettings', 'settingsversion') | |||
|
|||
# Process SQL queries first20bytesofencryptedmessage in table inventory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this section can probably be deleted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/class_sqlThread.py
Outdated
item = '''update settings set value=? WHERE key='version';''' | ||
parameters = (2,) | ||
self.cur.execute(item, parameters) | ||
|
||
# People running earlier versions of PyBitmessage do not have the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lines 201-227 can be made into a separate method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lines 227-292 can be split into 2 or 3 methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, please check the method name.
src/tests/test_sqlthread.py
Outdated
|
||
# Test versions | ||
upgrade_db = UpgradeDB() | ||
upgrade_db._upgrade_one_level_sql_statement(int(version)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# pylint: disable=protected-access
f335968
to
560c2ba
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make the requested changes.
src/class_sqlThread.py
Outdated
return None | ||
|
||
# Migrate Db with level | ||
method_name = 'upgrade_schema_data_' + str(level) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this defined anywhere, so delete this method.
item = '''update settings set value=? WHERE key='version';''' | ||
parameters = (level + 1,) | ||
self.cur.execute(item, parameters) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be more transparent. For example, you can use a @property
decorator for properties sql_schema_version
and configparser_schema_version
and use these instead calling the methods directly. And setter can enforce a +1
irrespective of what you pass as an argument.
It is certainly an improvement but still work left to do. |
c04cc05
to
a00c898
Compare
Closing because having changes in #1794 |
No description provided.