-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
Default filters for anonymous users #1087
Conversation
Note: https://meta.codidact.com/posts/288886 is still an issue with this, which is really bad because users cannot change the category filter. |
This leaves blank as Default instead
The above issue has been hopefully fixed with the last commit by adding an explicit System "None" option to the seeds. |
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.
Looks good.
Tested in local development environment:
- Default for category is applied and appropriate message shows:
- When no user is signed in.
- When a user is signed in with no user default for that category.
- Default for user is applied when present and signed in.
- Default can be overridden to "None":
- When it is the category default and there is no user signed in.
- When it is the category default and there is a user signed in.
- When it is the user default.
- "None" can be cleared, resulting in the correct default being restored.
Deploying to production
Note that I ran the following in order to add the new "None" filter and to get it to show up in the user interface:
rails db:seed
redis-cli flushall
That second one clears all of the redis cache, so causes all the new activity indicator circles to appear on all categories. This is not ideal for deploying to production. Is there a more precise approach that will just clear the cache aspect relating to the filters?
Clearing the whole redis cache is bad (annoys everyone). If we can't selectively flush just the part we need, what happens here if we don't flush it at all? Is there a way to instead push in the changes we want, without flushing stuff we don't want to lose? |
Very agreed that clearing the whole cache is to be avoided if at all possible. I don't know a way of pushing in just the changes we need, but it seems likely that this would be possible - hopefully someone else will be able to tell us how? In the meantime, could we avoid merging this one so it doesn't hold up deploys? Is there anything we can change about it to prevent accidentally merging? The merge is currently blocked by merge conflicts but I'm not sure whether resolving those allows immediate merging or requires another review (that is, I'm not sure if the repo is configured to insist on a new review after any new commit). |
@MoshiKoi This has merge conflicts preventing it from being merged into develop. If resolving those results in it asking for another review, feel free to ping me. |
@cellio I just realised I didn't answer the other part of your question: At least in my local development environment, not clearing the cache means that the predefined filters have no "None" option. This means that pressing "Clear" clears the filter back to the category or user default, so there is no way of applying no filters. An insightful user could create their own new filter which behaves the same way as "None", but I wouldn't want to depend on that as a workaround, especially as it is not an option when not signed in. I'd personally prefer that we not have default filters until we also have the "None" filter. |
If this is a system filter, then we should be able to just clear the key "system_filters" (which we should perhaps have expire automatically after some amount of time to periodically refresh it anyway?) Relevant code is in To clear only the system filters, run the following in a Community.all.each do |c|
RequestContext.community = c
Rails.cache.delete('system_filters')
end |
If we change the first line of system_filters = Rails.cache.fetch 'default_system_filters', expires_in: 1.day do Then it will recompute the system filters every day. I changed the name of the key (otherwise it will never apply the expiry) and added the |
Since this pull request is from a fork, I don't think anyone but MoshiKoi can push commits to it. To work around this I've changed the base branch of this pull request to a new branch of the same name on the main QPixel repository. My hope is that this will allow continuing work with Taeir's cache fix on the new branch, which can then be merged into I haven't yet merged this, for 2 reasons:
|
@Taeir I believe you told me that when the only difference in |
@cellio that is correct. |
@Taeir thanks for explaining that we can still make commits even though the branch is on MoshiKoi's fork. I have therefore changed the base branch back to I have now merged in develop, taking the latest date in Since we'll now be able to make your suggested cache change on this branch, I'll try to do that when I'm next at a computer. |
As suggested in Taeir's comment: codidact#1087 (comment)
I have made a further commit so I'd like someone else to review this.
I've made @Taeir's suggested change so that the system filters cache will be refreshed without needing to delete any other caches. This seems like a good idea to me, but I am not yet familiar with how Rails caches work, and have run into problems trying to understand them in other contexts. For this reason I'd like this to be reviewed by someone else. Also, I generally try to avoid reviewing anything I have made a commit to. |
@ArtOfCode- can you take a look at the rails question in the previous comment? |
Hopefully resolves #1043
Proof of concept, hasn't been fully tested yet.
For anon users, it defaults to the category default
For signed-in users, it defaults first to their default if it exists, then to the category default
I put the default filter setting with the rest of the category settings, so only admins can edit it.