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

Technical debt #165

Open
iragm opened this issue Jul 13, 2024 · 1 comment
Open

Technical debt #165

iragm opened this issue Jul 13, 2024 · 1 comment
Labels
on hold This issue is on hold for now, we'll address it down the road

Comments

@iragm
Copy link
Owner

iragm commented Jul 13, 2024

A large chunk of this project was written in a single week. It was the first django project I'd ever built, and it shows. Now that auction.fish has grown to the point where others are contributing code, there's hundreds of daily visitors, and dozens of clubs actively using the site, it's time to think about refactoring some of the petco-tier code.

First, the site is "feature-complete", everything (?) works, and there's no roadmap towards a "version 2".

Second, I get near-daily requests for new features and a lot of these are really excellent ideas worth implementing, so development seems to be ongoing.

Here is a list of some of the stuff that I'm not super proud of:

  • Tests. The tests are very incomplete, use sqlite instead of mysql, and need to be reafactored to use a single base class that sets up an auction, users, etc. ChatGPT can bang out test for most views in seconds once the base class has been created. I don't see a need to have 100% test coverage, but certainly a test for each model property and a couple tests per view (logged in, not logged in, joined auction, auction admin) are needed.
  • Views. There are still some function based views that need to be rewritten as class based viewed. And many, many views look for auction in dispatch and can be refactored to use a common AuctionViewMixin
  • Signals. Need to be split into signals.py.
  • Location. GeoDjango didn't work when I played around with it 4 years ago, so location stuff uses a function called distance_to(). It works great, but there's quite a bit of redundancy in the code. Either move to GeoDjango, or create a new class that adds annotates get_queryset() with distance_to(), sets that latitude and longitude from cookies/userdata as appropriate, and puts up a "hey set your location" message if needed.
  • Emails. It's quite hard to test things as they are. There's a lot of code that's currently in management commands; this should be moved to a model properties. As an example, see auctiontos_notifications.py, which does a lot of stuff. Instead, it could just fetch all auctiontos where x email has not been sent, loop over them, send the email and mark sent if appropriate and that's it.
  • On the note of emails, we need to move from cronjobs to celery - there's enough different tasks at this point that it's worth working on this, although the cronjobs all work without issue.
  • Directly related to model properties, celery, and management commands, endauctions.py is a critical piece of this project and it's a mess of code.
    • Moving actions to model properties would make it much more readable
    • Sold lots could be omitted (if we set active=False when buying now)
    • The filter that's used to find lots could easily select only lots that are ending gte=now, and a separate filter could be used to send the "ending soon" websocket message
    • Again, because it works as-is, this isn't a high priority, but it could just be so much more efficient
  • Security. Overall the security is pretty good, but it's managed in several different functions (for images, lots, auctiontos, auctions, etc.). An issue was reported (UI for editing lots is inconsistent #193) and although this issue caused a user that should have had permission to not have permission, it's possible that other issues exist. (I did review the code and didn't see anything alarming, but still). While the site does not handle payments and the worst that can happen is leaking someone's email, there's absolutely no reason not to refactor the security code and add full test coverage for it. Rather than the single class and then some random functions called here and there, there should be a single class which calls a permissions_check in dispatch.
  • Try/except code: A lot of the try except code can be removed altogether, for example the UserData is now always created as soon as the user is saved, so it can be accessed at user.userdata without a try except block. There's also a lot of places where a dict.get() with a default value is a lot cleaner than try except.

All of this stuff has been back-burned for years now, but PRs to fix anything are more than welcome.

@iragm iragm added the on hold This issue is on hold for now, we'll address it down the road label Aug 18, 2024
@iragm iragm closed this as not planned Won't fix, can't repro, duplicate, stale Aug 18, 2024
@iragm iragm changed the title Celery for tasks Technical debt Aug 31, 2024
@iragm iragm reopened this Aug 31, 2024
@jamescurtin
Copy link
Collaborator

Happy to help here; will submit a PR (or two) to kick this off sometime later this weekend.

iragm pushed a commit that referenced this issue Aug 31, 2024
iragm pushed a commit that referenced this issue Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on hold This issue is on hold for now, we'll address it down the road
Projects
None yet
Development

No branches or pull requests

2 participants