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

core.models.update_category_home improvements #31

Open
anibalpacheco opened this issue Jan 20, 2022 · 1 comment
Open

core.models.update_category_home improvements #31

anibalpacheco opened this issue Jan 20, 2022 · 1 comment
Assignees

Comments

@anibalpacheco
Copy link
Contributor

anibalpacheco commented Jan 20, 2022

There is a comment in the function that says to improve the stop condition when there are fixed articles (for this categories, the needed value would be less than the hardcoded value of 10).

DONE iterate over ArticleRel.edition.date_published ranges, this way, in a very populated environment (the most probable scenario) we can achieve goals in the first range iteration, that would be much faster than execute the whole join with no date restriction.

DONE Another improvement: the most inner for iterates over all categories, this can be easily improved into an iteration over only those categories that need more articles, pseudo:

categories_to_fill = settings.CORE...

if categories_to_fill:
    ...
    for edition in ...
        for ar in ...      
            if categories_to_fill:
                article = ...
                for cat in categories_to_fill:
                    if article matches criteria to enter:
                        append the article
                    if now this cat is full:
                        remove it from the categories_to_fill list
            else:
                stop = True
                break
    if stop:
        break

DONE But also there is another good thing to do there: when the home is not fully-filled, is much probable that there aren't more articles than this number, so, we can previously count them (new Category method) to know which is the new max value and also decrease the "needed" value to this counter (in a per-category way), this avoids the unnecessary loop until the oldest edition that will not find anything.

Of course this improvements not cover all the scenarios that can run the "complete" loop, but minimizes them in a very good way.

DONE important PD: the hardcoded value "11" should also be reviewed, because we need 10, the value is used to iterate over a range that could be easily fixed later with a simple "+1". check, fix and test this improvement before doing anything else.

@anibalpacheco anibalpacheco self-assigned this Jan 20, 2022
@anibalpacheco
Copy link
Contributor Author

TODO: check when there are 2 articles and then the first one is "unpublished", it seems that its place is filled again with the article left and causes a duplication (maybe a "cleaning" is needed after the fill algorithm at the end of the function)

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

No branches or pull requests

1 participant