def METHOD_NAME(chunk_size, explain):
    count_query = """
        select count(*) from sms_messagingsubevent where
        sms_messagingsubevent.xforms_session_id is not null
        and sms_messagingsubevent.date_last_activity is null
    """
    query = f"""
        update sms_messagingsubevent set date_last_activity = greatest(
            sms_messagingsubevent.date, sess.modified_time
        )
        from smsforms_sqlxformssession sess where sms_messagingsubevent.xforms_session_id = sess.id
        and sms_messagingsubevent.id in (
            select id from sms_messagingsubevent where
            sms_messagingsubevent.xforms_session_id is not null
            and sms_messagingsubevent.date_last_activity is null
            limit {chunk_size}
        )
    """
    return run_query_until_no_updates("xform_session", query, count_query, explain)