-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stored Favorite / Membership Counts (#601)
* Linting changes to Management Command * Black Formatting Changes * Remove Postgres Files * Remove Docker Compose Changes * Add Back Volumes from Docker Compose * Another Docker Compose Fix * Bulk Update and Testing * Merge in New Master * Re-generate Pipfile.lock * Revert Pipfile to wildcard Python 3 and re-gen lock file using 3.8 --------- Co-authored-by: Shiva Menta <shivamenta@ist2-07013.apn.wlan.private.upenn.edu> Co-authored-by: Shiva Menta <shivamenta@ist2-03085.apn.wlan.private.upenn.edu> Co-authored-by: Julian Weng <julian.weng.us@gmail.com>
- Loading branch information
1 parent
1f34b8b
commit fc28c42
Showing
9 changed files
with
1,620 additions
and
1,286 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.db.models import Count, Q | ||
|
||
from clubs.models import Club | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Update stored favorite and membership counts." | ||
|
||
def handle(self, *args, **kwargs): | ||
try: | ||
queryset = Club.objects.all().annotate( | ||
temp_favorite_count=Count("favorite", distinct=True), | ||
temp_membership_count=Count( | ||
"membership", distinct=True, filter=Q(active=True) | ||
), | ||
) | ||
|
||
for club in queryset: | ||
club.favorite_count = club.temp_favorite_count | ||
club.membership_count = club.temp_membership_count | ||
Club.objects.bulk_update(queryset, ["favorite_count", "membership_count"]) | ||
|
||
self.stdout.write( | ||
self.style.SUCCESS( | ||
"Successfully updated all club favorite and membership counts!" | ||
) | ||
) | ||
except Exception as e: | ||
self.stdout.write( | ||
self.style.ERROR( | ||
"An error was encountered while updating" | ||
+ "club favorite and membership counts!" | ||
) | ||
) | ||
self.stdout.write(e) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Generated by Django 3.2.18 on 2023-10-19 21:30 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("clubs", "0090_auto_20230106_1443"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="club", | ||
name="favorite_count", | ||
field=models.IntegerField(default=0), | ||
), | ||
migrations.AddField( | ||
model_name="club", | ||
name="membership_count", | ||
field=models.IntegerField(default=0), | ||
), | ||
migrations.AddField( | ||
model_name="historicalclub", | ||
name="favorite_count", | ||
field=models.IntegerField(default=0), | ||
), | ||
migrations.AddField( | ||
model_name="historicalclub", | ||
name="membership_count", | ||
field=models.IntegerField(default=0), | ||
), | ||
] |
This file contains 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Generated by Django 3.2.18 on 2024-01-24 17:27 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("clubs", "0091_auto_20231019_1730"), | ||
("clubs", "0094_applicationcycle_release_date"), | ||
] | ||
|
||
operations = [] |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: "3" | ||
|
||
services: | ||
db: | ||
image: postgres | ||
command: postgres | ||
environment: | ||
- POSTGRES_DB=postgres | ||
- POSTGRES_USER=penn-clubs | ||
- POSTGRES_PASSWORD=postgres | ||
ports: | ||
- "5432:5432" | ||
volumes: | ||
- ./postgres:/var/lib/postgresql/pgdata |
This file contains 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
This file contains 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