-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Sitemap sort order priorities updated #5724
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8a23646
Sitemap sort order priorities updated
saadmk11 f2f392b
ordering fix
saadmk11 65bfd9b
doc string fix
saadmk11 6e7a87e
sort_by_priority function added to sitemap
saadmk11 6fecc6b
lint fix
saadmk11 55f6f3e
Sorting by swapping positions
saadmk11 6175b66
index out of range issue fix
saadmk11 d959933
Merge branch 'master' into sitemap-sort-order
saadmk11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -351,7 +351,7 @@ def priorities_generator(): | |
It generates values from 1 to 0.1 by decreasing in 0.1 on each | ||
iteration. After 0.1 is reached, it will keep returning 0.1. | ||
""" | ||
priorities = [1, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2] | ||
priorities = [0.9, 1, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2] | ||
yield from itertools.chain(priorities, itertools.repeat(0.1)) | ||
|
||
def hreflang_formatter(lang): | ||
|
@@ -379,6 +379,14 @@ def changefreqs_generator(): | |
changefreqs = ['daily', 'weekly'] | ||
yield from itertools.chain(changefreqs, itertools.repeat('monthly')) | ||
|
||
def sort_by_priority(version_list): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this argument could be called just |
||
"""Sorts the versions by priority. i.e: 1, 0.9, 0.8...""" | ||
return sorted( | ||
version_list, | ||
key=lambda version: version['priority'], | ||
reverse=True | ||
) | ||
|
||
if project.privacy_level == constants.PRIVATE: | ||
raise Http404 | ||
|
||
|
@@ -431,7 +439,7 @@ def changefreqs_generator(): | |
versions.append(element) | ||
|
||
context = { | ||
'versions': versions, | ||
'versions': sort_by_priority(versions), | ||
} | ||
return render( | ||
request, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can leave this list sorted as it was, to avoid confusions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we change this
won't work. then we'll have to take another approach. So, I'll try another approach but this seem to have less complexity :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not changing the order of
changefreqs_generators
to returnweekly
first?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing the order of
changefreqs_generators
won't set the priority of stable to1
and latest to0.9
.priorities = [0.9, 1, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2]
this is the easiest way to set the priority correctly and also get the
changefreq
in order.i.e:
otherwise we have to look for another solution for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or we have to define a function like this inside the sitemap view which will sort the versions keeping stable as the first position
https://github.com/rtfd/readthedocs.org/blob/900c57532a3199ffdb8975b732eade1be87a6e5c/readthedocs/projects/version_handling.py#L42-L65
even though we are calling it (
comparable_version
) from here, we have to remove this with the function we createhttps://github.com/rtfd/readthedocs.org/blob/900c57532a3199ffdb8975b732eade1be87a6e5c/readthedocs/core/views/serve.py#L385
let me know if there is a better approach then this one or the previous one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was saying this because returning
[0.9, 1...]
contains some logic hidden in the woods. What we want in the end is assign 1 tostable
an 0.9 tolatest
.To keep things simple, why not just swapping these two versions from the result returned by
sort_version_aware
. Like,It's not good either, but at least it does not hide logic and show the problem explicitly.
I'm not sold in any of the "solutions" that I'm proposing. Follow the one that you feel it's better, more legible and maintainable. Whatever you choose, please add a comment in the correct place explaining what's happening and how is the sorting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I thought about swapping but it felt like a hacky way and wasn't able find anything simpler to do thats why I was asking you if you know of a better way.
I think we Shouldn’t go for a too complex way to do this small thing. Swapping is simple enough. I think I'll go with your idea with a good comment :)