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

#880 Create CatalogBlock model #925

Merged
merged 4 commits into from
Jul 4, 2019
Merged

#880 Create CatalogBlock model #925

merged 4 commits into from
Jul 4, 2019

Conversation

ArtemijRodionov
Copy link
Contributor

Closes #880

@ArtemijRodionov ArtemijRodionov requested a review from duker33 July 2, 2019 09:36
@ArtemijRodionov ArtemijRodionov self-assigned this Jul 2, 2019
Copy link
Contributor

@duker33 duker33 left a comment

Choose a reason for hiding this comment

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

one important note about pdd subtask. Several minor mistakes. And one interesting naming



class CatalogBlock(models.Model):
"""Catalog block is an element of catalog matrix UI element."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"""Catalog block is an element of catalog matrix UI element."""
"""Catalog block is an UI element of catalog matrix."""

)


class CatalogBlock(models.Model):
Copy link
Contributor

Choose a reason for hiding this comment

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

MatrixBlock or CatalogMatrixBlock.
It will be used only for Matrix page which is always for Catalog.

If you'll rename it, keep in mind CatalogBlockManager and the name in tests

def url(self):
self.category.url

def rows(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def rows(self):
def rows(self) -> CategoryQuerySet:

class CatalogBlock(models.Model):
"""Catalog block is an element of catalog matrix UI element."""

# @todo #880:60m Add it to the admin panel, use it in the matrix view.
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Add it -> Add CatalogBlock. It'll be header in the long tasks list.

  2. Here we have two pretty different tasks:

  • Use CatalogBlock at the matrix view
  • Add CatalogBlock to the admin panel
  1. And the first one is for 60m including tests, not for 30m. But it's up to you.
  2. CategoryBlock should be inline on Category Edit page on the admin panel

def test_get_catalog_blocks(self):
"""Perform four queries to fetch in batch blocks, categories, pages and category's children."""
roots = Category.objects.filter(level=0)
roots_count = roots.count()
Copy link
Contributor

Choose a reason for hiding this comment

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

we can use roots.count() directly, without var

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It'll bring an additional query to assertNumQueries(4) scope, that doesn't related to the test

@@ -86,3 +86,32 @@ def test_get_brands_from_products(self):
p: p.tags.filter(group__name=settings.BRAND_TAG_GROUP_NAME).first()
for p in products
}

def test_get_catalog_blocks(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def test_get_catalog_blocks(self):
def test_get_catalog_blocks_queries(self):

The name will able us to get rid from pydoc. It just doubles code lines now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is already in a relevant class QueryQuantities, so I'll remove the comment

for category in roots:
CatalogBlock.objects.create(category=category)

with self.assertNumQueries(4):
Copy link
Contributor

Choose a reason for hiding this comment

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

This structure would be more clear. Up to you

with self.assertNumQueries(1):
    # fetch blocks
with self.assertNumQueries(3):
    # fetch category, page, rows

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks better, but blocks can't be fetched in 1 query, because of select_related('category', 'cateogyr__page') and rows takes 2 queries, so this structure be more relevant:

with self.assertNumQueries(2):
    # fetch blocks, category, page
with self.assertNumQueries(2):
    # fetch rows

P.S.: To make clear the point about select_related

select_related gets the related objects in the same database query

block = CatalogBlock.objects.create(category=first)
sized_block = CatalogBlock.objects.create(category=second, block_size=2)

self.assertNotEquals(first.children.active(), len(sized_block.rows()))
Copy link
Contributor

Choose a reason for hiding this comment

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

you are comparing QS with number here. Let me suggest what you meaned

Suggested change
self.assertNotEquals(first.children.active(), len(sized_block.rows()))
self.assertEquals(first.children.active().count(), sized_block.rows().count())

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 for the mess. I have reworked the test

@duker33
Copy link
Contributor

duker33 commented Jul 3, 2019

@artemiy312 , i guess your code contains too many work for 1h. I recommend you to increase task price to 2h

@ArtemijRodionov ArtemijRodionov requested a review from duker33 July 4, 2019 08:49
@ArtemijRodionov ArtemijRodionov merged commit 6ed0777 into master Jul 4, 2019
@ArtemijRodionov ArtemijRodionov deleted the 880-matrix-rework branch July 4, 2019 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

catalog.py:45-47: Improve categories matrix arch. Now...
2 participants