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

Calendar Performance Update #241

Merged
merged 5 commits into from
Feb 9, 2024
Merged

Calendar Performance Update #241

merged 5 commits into from
Feb 9, 2024

Conversation

judtinzhang
Copy link
Member

No description provided.

except (ValueError, IndexError):
pass

if date and current_time.replace(tzinfo=None) < date.replace(tzinfo=None) < (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashleyzhang01 could you explain this line here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set the time zone for current_time to none because couldn't compare the datetime.datetime.now() with the date due to some time zone error. I guess if we moved back to the Django timezone, we might not have to do this since when we were using it before, that wasn't an issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, yea will revert back to timezone

date = models.CharField(max_length=50, null=True, blank=True)
# NOTE: This is bad practice, though is necessary for the time being
# since frontends use the string date field
date_obj = models.DateTimeField(null=True, blank=True)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to change this in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have fields for a start date and a nullable end date bc some calendar events are ranges.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the reminder. I will leave this for you to do in a future events PR you create so we can group relevant code

def get_queryset(self):
return CalendarEvent.objects.filter(
date_obj__gte=timezone.localtime(),
date_obj__lte=timezone.localtime() + timedelta(days=30),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now we need this because we never clear the database. @ashleyzhang01 what do you think? Do you think the manage.py command should delete all previous CalendarEvents that way we don't have to re-do this filtering for events?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't call the manage.py thing often enough that it deletes all previous. I had something in my Calendar method in the views.py for this-- can you move it in too?
Basically, it deletes any previous events when called each time, so we don't have to do the manage.py as often and don't have to filter through the time range as often.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, just did

def get_queryset(self):
return CalendarEvent.objects.filter(
date_obj__gte=timezone.localtime(),
date_obj__lte=timezone.localtime() + timedelta(days=30),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait also if it is only called once a month, then by the end of the month there won't be many future events left in the db, so we wouldn't really have any calendar events?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes good point. I'll change the get_calendar to create CalendarEvents that exceed 30 days as well. Then we will leave this view as is.

Copy link
Contributor

@tuneerroy tuneerroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good :)

def handle(self, *args, **kwargs):
# scrapes almanac from upenn website
try:
resp = requests.get("https://almanac.upenn.edu/penn-academic-calendar")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm could we make this a constant value, similar to how its handled here. and if we make the constant a name like UPENN_ALMANAC_WEBSITE then we can also get rid of the comment above since its self-explanatory

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds gooood tanner :D



class Command(BaseCommand):
def handle(self, *args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know a lot of this code was just moved but if u understand it, could we break this function down into more modular components? the super nested try-except statements are a bit hard to read.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. just cleaned it up to make it more readable.

Copy link

codecov bot commented Feb 9, 2024

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (7899494) 91.32% compared to head (bb0d0d5) 91.44%.

Files Patch % Lines
...ckend/penndata/management/commands/get_calendar.py 94.87% 2 Missing ⚠️
backend/penndata/models.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #241      +/-   ##
==========================================
+ Coverage   91.32%   91.44%   +0.11%     
==========================================
  Files          58       59       +1     
  Lines        2491     2502      +11     
==========================================
+ Hits         2275     2288      +13     
+ Misses        216      214       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@ashleyzhang01 ashleyzhang01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ashleyzhang01 ashleyzhang01 merged commit ebbc2b5 into master Feb 9, 2024
9 checks passed
@ashleyzhang01 ashleyzhang01 deleted the ashley/calendar branch February 9, 2024 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants