-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Refactor utils connect db #769
Refactor utils connect db #769
Conversation
Refactored one of db connections. more to follow.
pyspider/database/__init__.py
Outdated
return ResultDB(path) | ||
else: | ||
raise LookupError | ||
return _connect_sqlite(parsed,dbtype) | ||
elif engine == 'mongodb': | ||
url = url.replace(parsed.scheme, 'mongodb') |
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.
The url replacement logic should be a part of _connect_mongodb
.
pyspider/database/__init__.py
Outdated
from .mongodb.resultdb import ResultDB | ||
return ResultDB(url, **parames) | ||
else: | ||
raise LookupError | ||
elif engine == 'sqlalchemy': | ||
if not other_scheme: |
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.
same for _connect_sqlalchemy
pyspider/database/__init__.py
Outdated
@@ -154,23 +92,104 @@ def _connect_database(url): # NOQA | |||
raise LookupError('not supported dbtype: %s', dbtype) | |||
elif engine == 'elasticsearch' or engine == 'es': | |||
# in python 2.6 url like "http://host/?query", query will not been splitted |
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 comment is for L157, should be moved as well.
pyspider/libs/utils.py
Outdated
elif days < 334: # 11mo, since confusing for same month last year | ||
format = "%(month)s-%(day)s" if shorter else \ | ||
"%(month)s-%(day)s at %(time)s" | ||
ret_, ret_format = fix_full_format(days, seconds, relative, shorter, local_date, local_yesterday) |
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.
The refectory here is not correct. The original code is to generate a format
, it has to be filled with actual date information in L140, it shouldn't be returned directly.
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'm not sure what's incorrect compared to the original code. The original code has three "direct" return calls after the decision point "if relative and days == 0:" at line 109 of the original code. Which are the three cases we return in the refactoring.
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.
Thank you for your work. The refactoring to database connection looks reasonable. But still need some changes.
* part 1 * [Doc] Update coverage links for the fork * Refactor. Changes to utils and _connect_db * Refactored in utils Refactored one of db connections. more to follow. * Refactor. Split up some more connects * Rm. Removed unused textfile * Doc. rewrote README.md to original * Refactor. Wrong variable name fix. * Refactor, applied suggested changes in the review in the database connector. * Refactor, changed name of return variable gotten from fix_full_format in format_date
We a group of students have been looking at coverage and cyclomatic complexity on this repository and as an extra part of our assignment we're looking to get our refactor accepted. This pull request lowers the cyclomatic complexity of the functions _connect_database@49-176@./pyspider/database/init.py and format_date@72-147@./pyspider/libs/utils.py, By splitting the functions up at logical points.