creativecommons / legaldb

CC Legal Database: curated repository of Case Law and Scholarship data from around the world in a Django based website.
https://LegalDB.CreativeCommons.org/
MIT License
46 stars 69 forks source link

refactor get_request_message to use next() for improved performance #233

Closed Faith-K-commits closed 1 month ago

Faith-K-commits commented 1 month ago

Fixes

Description

This pull request simplifies the get_request_message function by refactoring it to use a generator expression, removing the need for explicitly looping through the messages list. The new implementation leverages Python’s next() to directly return the first relevant message containing "scholarship" or "case" or None if none is found.

Technical details

The previous version of the get_request_message function used a for loop to iterate through the messages. The refactored version uses a more concise next() function with a generator expression. This results in clearer and more efficient code.

Tests

  1. Ensure that messages containing "scholarship" or "case" are properly returned.
  2. Confirm that if no message matches, None is returned.
  3. Test edge cases such as empty messages and different message formats.

Checklist

Developer Certificate of Origin

For the purposes of this DCO, "license" is equivalent to "license or public domain dedication," and "open source license" is equivalent to "open content license or public domain dedication."

Developer Certificate of Origin ``` Developer Certificate of Origin Version 1.1 Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 1 Letterman Drive Suite D4700 San Francisco, CA, 94129 Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. ```
TimidRobot commented 1 month ago

Tests

command:

docker compose exec app ./manage.py test

output excerpt:

Ran 13 tests in 2.563s

OK
TimidRobot commented 1 month ago

Deployed to Production

Per deploy_to_heroku.md:

git push heroku main; date
Enumerating objects: 37, done.
Counting objects: 100% (36/36), done.
Delta compression using up to 10 threads
Compressing objects: 100% (23/23), done.
Writing objects: 100% (23/23), 6.56 KiB | 6.56 MiB/s, done.
Total 23 (delta 15), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Updated 147 paths from bba4b23
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-24 stack
remote: -----> Using buildpack: heroku/python
remote: -----> Python app detected
remote: -----> Using Python 3.12 specified in Pipfile.lock
remote: -----> Using cached install of Python 3.12.7
remote: -----> Installing pip 24.0, setuptools 70.3.0 and wheel 0.44.0
remote: -----> Installing Pipenv 2024.0.1
remote: -----> Installing SQLite3
remote: -----> Installing dependencies with Pipenv
remote:        Installing dependencies from Pipfile.lock (2b6da2)...
remote: -----> $ python manage.py collectstatic --noinput
remote:        480 static files copied to '/tmp/build_c2cf67c7/staticfiles', 884 post-processed.
remote: 
remote: -----> Discovering process types
remote:        Procfile declares types -> release, web
remote: 
remote: -----> Compressing...
remote:        Done: 62.9M
remote: -----> Launching...
remote:  !     Release command declared: this new release will not be available until the command succeeds.
remote:        Released v67
remote:        https://fast-eyrie-10628.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
remote: Running release command...
remote: 
remote: Operations to perform:
remote:   Apply all migrations: admin, auth, contenttypes, legal_db, sessions, taggit
remote: Running migrations:
remote:   No migrations to apply.
To https://git.heroku.com/fast-eyrie-10628.git
   475900b..fd63eb3  main -> main
Tue Oct 22 07:22:04 PDT 2024
Faith-K-commits commented 1 month ago

You're welcome @TimidRobot