-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
4230 search query suggested changes #4479
base: main
Are you sure you want to change the base?
Conversation
changes made to models.py and views.py to save user queries Fixes: #4230
for more information, see https://pre-commit.ci
🔍 Existing Issues For ReviewYour pull request is modifying functions with the following pre-existing issues: 📄 File: cl/search/views.py
Did you find this useful? React with a 👍 or 👎 |
"{path}?next={next}{encoded_params}".format( | ||
path=reverse("sign-in"), | ||
next=request.path, | ||
encoded_params=quote(f"?{request.GET.urlencode()}"), | ||
) |
Check warning
Code scanning / CodeQL
URL redirection from remote source Medium
user-provided value
Copilot Autofix AI 11 days ago
Copilot could not generate an autofix suggestion
Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.
- Add tests for SearchQuery creation - Update user ForeignKey to on_delete=models.CASCADE, to match specs
f3d2abf
to
4652fe6
Compare
Yeah, you're right. Let's just do a date_created field.
I'm not sure, but I think that might not do what we want. Do you know if it keeps counting while we want for network requests? I think the Python speed isn't very interesting and the important part is the Elastic speed. Also: Does counting nanoseconds take more CPU time? If so, it's not really worth doing. I think they'll be harder to reason about too.
Yes. We should log all this stuff and the API too. We might want to add a boolean for API requests though, so they're separate from the rest. Some API users do really weird (and slow) stuff compared to actual users.
We'll need to get that from the downstream function. Maybe it can return whether the cache was used? Thank you, Gianfranco! |
Some details and questions:
I didn't want to commit directly on Sergei's branch, so I intended for this to be PR over that branch, but I see Github has interpreted it as a PR on main, even when I branched from it
Setting
on_delete=models.CASCADE
to the User FK follows this comment from the original issue:Should we really use
AbstractDateTimeModel
as base class forSearchQuery
? Are we ever going to modify the SearchQuery once it happens? In case we don't, there is no use for thedate_modified
field and it's index; and expecting this new table to have so many rows, we would save some space / speedAbout computing the "query_time_ms" using
time.perf_counter_ns
, it seems to be the most precise. Check the section in Python docs https://docs.python.org/3/library/time.html#time.perf_counter.Also, I noted that with these changes, we will only be capturing search queries from the main homepage/search for Case Law; it won't log queries for RECAP archive, citation search, parenthetical search, etc. Is it of interes to log that?
I took some freedom to refactor the
search.views.show_results
function, it could use early returns to reduce indentation levels, which were confusing since the if/else clauses are so long.I don't know how to compute the
hit_cache
field, we should probably ask Alberto how to know if ES or Solr were using the cache. I see that thedo_es_search
functions have a cache argument, but it's not used on theshow_results
function. For now, I have set it to False always