calendar: implement database trimming functionality.