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 public function in dump_manager #200

Merged
merged 2 commits into from Apr 16, 2018

Conversation

ferbncode
Copy link
Member

Refactor public function in dump_manager.py (Removing a lot of duplicate code) and using transaction for copying tables.

@paramsingh
Copy link
Collaborator

Do tests in #199 pass after these changes are applied?



def create_base_archive(dump_dir, temp_dir):
"""Creates a dump of all license-independent information: (users, license)."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

This docstring should be improved. Add information about what this function takes as arguments and what it returns.

print("Done!")


def create_base_archive(dump_dir, temp_dir):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like it would be better for readability and decoupling if we created a temp_dir in this function instead of passing it.

REVISION_COMBINED_SQL = """
SELECT {columns} FROM revision JOIN review
def create_reviews_archive(dump_dir, temp_dir, license_id=None):
"""Creates a dump of reviews filtered on the given license_id, their revisions and
Copy link
Collaborator

Choose a reason for hiding this comment

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

This docstring should be improved as well. You should also add what happens when license_id=None.

@@ -19,7 +20,6 @@
import critiquebrainz.db.review as db_review
import critiquebrainz.db.moderation_log as db_moderation_log
from critiquebrainz.frontend.external.musicbrainz_db.entities import get_multiple_entities, get_entity_by_id
from langdetect import detect
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change doesn't seem related to anything in this PR.

with open(os.path.join(base_archive_tables_dir, 'license'), 'w') as f:
cursor.copy_to(f, 'license', columns=_TABLES["license"])
except Exception:
print('Error while copying tables')
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should log the error as well. Also, the message should be something like error while copying tables during creation of base archive so that it is easier to understand where the error took place.

Copy link
Collaborator

@paramsingh paramsingh left a comment

Choose a reason for hiding this comment

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

🏅

@paramsingh paramsingh merged commit 176fba6 into metabrainz:master Apr 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants