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

CB-263: Update publication date of draft reviews on CritiqueBrainz when they get published #171

Merged
merged 14 commits into from Jun 16, 2018

Conversation

IsaacZanoria
Copy link
Contributor

add new column (publish_time) to review table which is only updated when a review is published without saving as a draft or changed from a draft to a published review. add to get_by_id() so that it gets put in the returned dictionary, and change html tempaltes to use the value from the new key

@brainzbot
Copy link
Member

Can one of the admins verify this patch?

1 similar comment
@brainzbot
Copy link
Member

Can one of the admins verify this patch?

@@ -322,7 +334,7 @@ def list_reviews(*, inc_drafts=False, inc_hidden=False, entity_id=None,
offset=None):
"""Get a list of reviews.

This function provides several filters that can be used to select a subset of reviews.
This function provides several filters that can be used to select a subset of reviews.
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi, it seems a space was added here by mistake

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, yeah, you're right, I'll remove that right away

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry about making more problems with one of the commits; I'm on a school computer and not having fun using the in-browser editor

is_hidden BOOLEAN NOT NULL,
license_id VARCHAR NOT NULL,
language VARCHAR(3) NOT NULL,
publish_time TIMESTAMP,
Copy link
Member

Choose a reason for hiding this comment

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

Let us make that publish_date to be more clear. :)

@@ -83,6 +84,7 @@ def get_by_id(review_id):
review.language,
review.source,
review.source_url,
review.publish_time,
Copy link
Member

Choose a reason for hiding this comment

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

Since we are adding another column to the table (for publish date), it is important to remove the subquery for creating created_time and the corresponding entry of created_time.created in SELECT, as that part is now unnecessary.

Copy link
Member

Choose a reason for hiding this comment

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

Also, for adding the Last Revised: information, you can make use of the revision.timestamp, so I would suggest it to rename the column as last_revision_timestamp.

@@ -220,6 +222,10 @@ def update(review_id, *, drafted, text=None, rating=None, license_id=None, langu
if is_draft is not None:
if not drafted and is_draft: # If trying to convert published review into draft
raise db_exceptions.BadDataException("Converting published reviews back to drafts is not allowed.")
if drafted and (not is_draft):
Copy link
Member

Choose a reason for hiding this comment

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

I think there is no need of the parentheses.

if drafted and not is draft:
    ... 

@ferbncode
Copy link
Member

ferbncode commented Jan 9, 2018

@IsaacZanoria Since it is a schema-change PR, you need to add a file in admin/schema_changes (9.sql) for altering table review for adding a column published_on.

@ferbncode
Copy link
Member

@IsaacZanoria There are more changes to be made for this PR to be merged:

  • Update the SCHEMA_VERSION variable in the db module.
  • Update _TABLES in data/dump_manager.py to include column published_on. Also, later the CB dumps need to be updated for this schema change.

@ferbncode
Copy link
Member

@brainzbot test this please

@ferbncode
Copy link
Member

ferbncode commented Jan 9, 2018

@IsaacZanoria See the Jenkins errors to fix the tests (Pytest). You need to update the tests involving the creation of test reviews.

Copy link
Member

@ferbncode ferbncode left a comment

Choose a reason for hiding this comment

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

You also need to update the function db.review.list_reviews and handle cases where published_on can be Null.

@@ -0,0 +1,5 @@
BEGIN;

ALTER TABLE review ADD COLUMN published_on TIMESTAMP;
Copy link
Member

Choose a reason for hiding this comment

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

There is no need of the BEGIN and COMMIT statements here.

@@ -1,6 +1,7 @@
import critiquebrainz.db.avg_rating as db_avg_rating
import critiquebrainz.db.exceptions as db_exceptions


Copy link
Member

Choose a reason for hiding this comment

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

This is unnecessary. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, ive seen a pep8 warning about "2 blank lines expected" in tests, and figured i'd just fix it

@@ -196,7 +196,7 @@ def test_list_reviews(self):
self.assertEqual(count, 1)
self.assertEqual(len(reviews), 1)

reviews, count = db_review.list_reviews(sort="created")
reviews, count = db_review.list_reviews(sort="")
Copy link
Member

Choose a reason for hiding this comment

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

I think you should put published_on as an argument here. This would test if the reviews are fetched successfully if ordered by publish date.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, i already have the "published_on" argument set up, i think i was in the middle of adding it here and got distracted, and ended up leaving it blank

Copy link
Member

Choose a reason for hiding this comment

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

No problem :)

@@ -93,23 +94,12 @@ def get_by_id(review_id):
"user".show_gravatar,
"user".musicbrainz_id,
"user".is_blocked,
created_time.created,
license.full_name,
license.info_url
FROM review
JOIN revision ON revision.review_id = review.id
JOIN "user" ON "user".id = review.user_id
JOIN license ON license.id = license_id
Copy link
Member

Choose a reason for hiding this comment

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

Please make sure that the query is right. I see that the WHERE clause is now missing. You can fix the query by adding a WHERE clause for the review_id. :)

@ferbncode
Copy link
Member

I think there is a bug in pylint version, which is the reason of all the new pylint errors (pylint-dev/pylint#1609). Could you please try updating the pylint version to 1.8.1. It should fix some pylint errors. The rest of the PR looks good :)

@ferbncode
Copy link
Member

Don't worry about the pylint fixes. It seems a version error and should be solved in a different PR.

Also, just saw your query on IRC regarding sorting on published_on in the db_review.list_reviews function. There is an argument include_drafts in the function set to False that should take care of our unpublished reviews. :)

@paramsingh
Copy link
Collaborator

The update script that accompanies this should also fill out the correct values in the new column added for all existing rows.

@@ -0,0 +1 @@
ALTER TABLE review ADD COLUMN published_on TIMESTAMP;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We'd also want to fill up the published_on column with values for old reviews.

And this should be inside a transaction.

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.

IsaacZanoria and others added 13 commits April 25, 2018 16:43
add new column (publish_time) to review table which is only updated when a review is published without saving as a draft or changed from a draft to a published review.  add to get_by_id() so that it gets put in the returned dictionary, and change html tempaltes to use the value from the new key
…A_VERSION value

also remove that "expect 2 blank lines" error PEP8 keeps on getting in views.test
all the other files had it, so i thought i'd be safe
test now sorts by new "published_on" column
Also, show both created date and published on date on
user review page.
@paramsingh
Copy link
Collaborator

@brainzbot add to whitelist

@paramsingh
Copy link
Collaborator

@ferbncode, this is ready for review, would you mind taking a look at the last two commits I made?

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.

OK to go for me.

🥇

Copy link
Member

@ferbncode ferbncode left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@paramsingh paramsingh merged commit 617bef4 into metabrainz:master Jun 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants