Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Refactor utils connect db #769

Merged
merged 11 commits into from
Mar 7, 2018
Merged

Refactor utils connect db #769

merged 11 commits into from
Mar 7, 2018

Conversation

M-swords
Copy link
Contributor

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.

return ResultDB(path)
else:
raise LookupError
return _connect_sqlite(parsed,dbtype)
elif engine == 'mongodb':
url = url.replace(parsed.scheme, 'mongodb')
Copy link
Owner

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.

from .mongodb.resultdb import ResultDB
return ResultDB(url, **parames)
else:
raise LookupError
elif engine == 'sqlalchemy':
if not other_scheme:
Copy link
Owner

Choose a reason for hiding this comment

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

same for _connect_sqlalchemy

@@ -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
Copy link
Owner

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.

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)
Copy link
Owner

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.

Copy link
Contributor Author

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.

Copy link
Owner

@binux binux left a 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.

@binux binux merged commit 01f125c into binux:master Mar 7, 2018
brian6peng pushed a commit to brian6peng/pyspider that referenced this pull request Jun 20, 2018
* 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants