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

Split CatalogPage's monolith code #550

Closed
duker33 opened this issue Aug 27, 2018 · 7 comments
Closed

Split CatalogPage's monolith code #550

duker33 opened this issue Aug 27, 2018 · 7 comments
Assignees
Labels
1 burning issue 2 hours some big and monolith issue with hard decisions, discussions or bug with strong research blocker this issue blocks another issue cleanup everything that do project stronger, flexible, reusable report Put it to completed tasks temporary list for business Tags STB's feature x4 task's price quadroed. Usually because of burning

Comments

@duker33
Copy link
Contributor

duker33 commented Aug 27, 2018

shopelectro.views.catalog.CategoryPage currently consists of this steps:

  • get products
  • filter tags
  • get template context
  • paginate products

All these steps are semantically separated from CategoryPage and from each other.
Here is good code draft example for get products + filter tags.

class CategoryPage:

    def __init__(self, category_id):
        pass

    def products(self) -> 'QuerySet':
        return None

    def get_context_data(self):
        return {}


class TaggedCategoryPage:
    def __init__(self, page: CategoryPage, tags):
        self.super = page

    def products(self) -> 'QuerySet':
        return super.products.filter(smth=anyth)

    def get_context_data(self):
        context = self.super.get_context_data()
        data = {}
        return {
            'all_products': products,
            **data,
            **context,
        }

But use in this task traditional inheritance instead of objects composition

@duker33 duker33 added 1 hour typical issue size. It's one pdd hour 1 burning issue blocker this issue blocks another issue cleanup everything that do project stronger, flexible, reusable Tags STB's feature labels Aug 27, 2018
@duker33 duker33 self-assigned this Aug 27, 2018
duker33 added a commit that referenced this issue Aug 27, 2018
@ArtemijRodionov
Copy link
Contributor

ArtemijRodionov commented Aug 28, 2018

@duker33
I believe, that inheritance is not the best solution for this issue.
Currently the implementation does not look helpful and even vice versa, because we are going to create a complex inheritance structure, that will decrease view performance and will be still monolith. And in final we will use only one class from this structure that can be presented as single class as it is right now

@duker33
Copy link
Contributor Author

duker33 commented Aug 28, 2018

@artemiy312 , inheritance is only step for objects composition.

But even with inheritance we'll switch to named chunks of code with separated responsibility. Instead of one huge get_context_method with all-in-one.

With inheritance responsibility will be separated, but badly organized.
And it's task of objects composition to organize it well.
We'll enable composition after this task tree will fully

class AbstractContext:
	def __init__(self, super: CatalogContext):
		self.super = super


class CatalogContext(AbstractContext):
	
    def products(catalog):
		return DB.fetch_prods(catalog)
		
	def get_context_data():
		return {...}  # something simple only about catalog

class TaggedCatalogContext:
    def products(tags):
		return self.super.products().and_aother_fetch(catalog)
		
	def get_context_data():
		return {
			**self.super.get_context_data(),
			... # and something simple only about tags
		}
		
class PaginatedCatalogContext:
	...
	
class DBTemplateContext:
	...

class CatalogView:
	def get_context_data(category_id, page_num):
		category = some_fetch(category_id)
		context = CatalogContext(category) | PaginatedCatalogContext(page_num)
		return context.get_context_data()

class TaggedCatalogView:
	def get_context_data(category_id, page_num, tags):
		category = some_fetch(category_id)
		context = (
			CatalogContext(category)
			| PaginatedCatalogContext(page_num)
			| TaggedCatalogContext(tags)
			| DBTemplateContext(tags)
		)
		return context.get_context_data()

In this case we can decrease amount of composited code for individual url

@duker33
Copy link
Contributor Author

duker33 commented Aug 29, 2018

discussed this task with Artemiy via call.
I'll implement objects composition in this task. I'll increase hours count for it

@duker33 duker33 added 2 hours some big and monolith issue with hard decisions, discussions or bug with strong research x2 task's price doubled. Usually because of burning and removed 1 hour typical issue size. It's one pdd hour labels Aug 29, 2018
duker33 added a commit that referenced this issue Aug 31, 2018
duker33 added a commit that referenced this issue Aug 31, 2018
duker33 added a commit that referenced this issue Aug 31, 2018
duker33 added a commit that referenced this issue Aug 31, 2018
duker33 added a commit that referenced this issue Sep 1, 2018
duker33 added a commit that referenced this issue Sep 3, 2018
@duker33
Copy link
Contributor Author

duker33 commented Sep 3, 2018

broke pdd rules here. So increase time. Wasted it for arch

@duker33 duker33 added x4 task's price quadroed. Usually because of burning and removed x2 task's price doubled. Usually because of burning labels Sep 3, 2018
duker33 added a commit that referenced this issue Sep 3, 2018
duker33 added a commit that referenced this issue Sep 3, 2018
duker33 added a commit that referenced this issue Sep 6, 2018
duker33 added a commit that referenced this issue Sep 7, 2018
duker33 added a commit that referenced this issue Sep 7, 2018
# Conflicts:
#	shopelectro/models.py
#	shopelectro/views/catalog.py
duker33 added a commit that referenced this issue Sep 7, 2018
duker33 added a commit that referenced this issue Sep 7, 2018
duker33 added a commit that referenced this issue Sep 7, 2018
duker33 added a commit that referenced this issue Sep 7, 2018
#550  Resolve branch inner conflicts

#550  Apply linter rules

#550  Review#2 fixes. Rm redundant pdd issue, fix imports

#550  Rm redundant pdd issue

#550  Pdd issue about context module improving

#550  Merge fixes after hell

#550  Minor self-review fixes

#550  Add code example for creating context

#550  Make context names shorten

#550  Fork AbstractPageContext

#550  Cleanup code

#550  Fork PaginationCategoryContext class

#550  Fork SortingCategoryContext class

#550  Fork DBTemplateContext class. Improve pipe mech

#550  Fork TaggedCategoryContext class

#550  Implement CatalogContext

#550  Fork SortingCategoryPage class

#550  Fork PaginatedCatalogPage class

#550  Fork DBContextCatalogPage class

#548  Apply E305 linter rule

#550  Review#1 fixes. Cache in memory db queries

#548  Rm E305 pycodestyle rule

#550  Add pdd issue for continue splitting

#550  Create TaggedCategoryPage class
duker33 added a commit that referenced this issue Sep 7, 2018
duker33 added a commit that referenced this issue Sep 7, 2018
duker33 added a commit that referenced this issue Sep 7, 2018
duker33 added a commit that referenced this issue Sep 7, 2018
* #550  Review#3 fixes. Rm get_tags caching

#550  Resolve branch inner conflicts

#550  Apply linter rules

#550  Review#2 fixes. Rm redundant pdd issue, fix imports

#550  Rm redundant pdd issue

#550  Pdd issue about context module improving

#550  Merge fixes after hell

#550  Minor self-review fixes

#550  Add code example for creating context

#550  Make context names shorten

#550  Fork AbstractPageContext

#550  Cleanup code

#550  Fork PaginationCategoryContext class

#550  Fork SortingCategoryContext class

#550  Fork DBTemplateContext class. Improve pipe mech

#550  Fork TaggedCategoryContext class

#550  Implement CatalogContext

#550  Fork SortingCategoryPage class

#550  Fork PaginatedCatalogPage class

#550  Fork DBContextCatalogPage class

#548  Apply E305 linter rule

#550  Review#1 fixes. Cache in memory db queries

#548  Rm E305 pycodestyle rule

#550  Add pdd issue for continue splitting

#550  Create TaggedCategoryPage class

* #550  Merge fixes

* #550  Fix shadowed var

* #550  Apply linter rules after rebase
@0pdd
Copy link
Collaborator

0pdd commented Sep 7, 2018

@duker33 4 puzzles #566, #567, #568, #569 are still not solved.

@duker33 duker33 added the report Put it to completed tasks temporary list for business label Sep 7, 2018
duker33 added a commit that referenced this issue Sep 11, 2018
duker33 added a commit that referenced this issue Sep 16, 2018
* rf#168  Inject products queryset to catalog context

* rf#168  Fix se#550's rebase. Inject tag qs tag context

* rf#168  Move tag_pairs stuff from catalog context to tags one

* rf#168  Broken code. Move to QS receive

* rf#168  Fix distinct-order_by bug

* rf#168  Implement new interface for `context.prepare_products`

* #550  Add minor pdd issue

* #550  Pdd issue to move context to refarm.catalog app

* rf#168  Grade refarm dep, minor fix in test_views

* rf#168  Apply linter rules
@0pdd
Copy link
Collaborator

0pdd commented Sep 16, 2018

@duker33 7 puzzles #566, #567, #568, #569, #577, #578, #579 are still not solved.

@0pdd
Copy link
Collaborator

0pdd commented Sep 17, 2018

@duker33 all 7 puzzles are solved here: #566, #567, #568, #569, #577, #578, #579.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 burning issue 2 hours some big and monolith issue with hard decisions, discussions or bug with strong research blocker this issue blocks another issue cleanup everything that do project stronger, flexible, reusable report Put it to completed tasks temporary list for business Tags STB's feature x4 task's price quadroed. Usually because of burning
Projects
None yet
Development

No branches or pull requests

3 participants