Rough Draft of Calendar Custom Component!

Still very much in development, but I thought I’d share what I have so far.

Just finished the caching logic, so if a given month / year, has information, it is pulled from the database.

Thanks to @jshaffstall for pointing out some stuff hiding in the Day object init, which ended up speeding up the month load times instantly!

Updates to the functionality will be posted here as they are completed:

https://anvil.works/build#clone:2YTMQUCIDGNA2IRB=MDMPBUZGUV37OUW2I35QNITS

2 Likes

That server call overhead can add up, and you’ve got a bunch of server calls happening for a single month display. Making a single server call to get all the info you need for all the components, and then passing it into the components would speed things up.

You could also cache month info in the client so that going back and forth between months requires no server calls.

4 Likes

“Making a single server call to get all the info you need for all the components, and then passing it into the components would speed things up.”
I agree, though, that’s what the caching does, unless I didn’t implement it correctly?

@anvil.server.callable
def get_weekday_week_num_collection(days_in_month, year, month):
  cached_values = try_get_cached_values(year, month)
  if cached_values:
    print('cached values were found, returning them now ...')
    return cached_values
  else:
    print('No cached values found for month, calculating ...')
    weekday_week_num_list = []
    for day_num in range(1, days_in_month + 1):
      weekday = weekday_from_date(year, month, day_num)
      week_num = week_number_from_date(year, month, day_num)
      weekday_week_num = {'weekday' : weekday, 'week_num' : week_num}
      weekday_week_num_list.append(weekday_week_num)
  append_weekday_week_num_list_to_cache(weekday_week_num_list, year, month)
  return weekday_week_num_list

Yes, I thought about doing some caching on the client side, good thought :slight_smile:

Your individual components are making server calls. Your Day object, for example makes a server call in its init. You’re creating a bunch of those for each month, each one making its own server call.

So every time you call render_month in the calendar object, you’re making 1 server call for the overall month and then individual server calls for each Day object.

If that 1 server call for the month gave you all the info you needed for the entire calendar, including the list of names of days you could pass to the Day objects so they could use it without making separate server calls, that’s what I was meaning.

That change alone would speed up display of the calendar by a lot.

2 Likes

DOH!

Good find man. Can’t believe I left that server call in the Day init :sweat_smile:

Loading each month is almost instant now :slight_smile:

2 Likes