• Nick Thomas's avatar
    Only set an ETag for the notes endpoint after all notes have been sent · b8ce7d1c
    Nick Thomas authored
    The ETag caching system we use assumes that all notes are sent in a
    single response, and makes that response the cached one. When a note
    is subsequently updated, the ETag is invalidated and the note thrown
    away.
    
    This is incompatible with pagination, which is currently behind a flag
    (appropriately, called `paginated_notes`. I *think* it also means that
    the clients end up parsing the cached response every poll-interval,
    which is less than ideal.
    
    One approach is to remove the ETag from this endpoint altogether, but
    this has some costs in terms of additional server load.
    
    In this commit, I introduce a mechanism to make the ETag conditional,
    and skip adding the ETag if there are any notes in the response. This
    means that:
    
    * Pagination will work correctly
    * The browser will only ever cache the empty response
    
    This means there will be one additional HTTP request before the ETag
    is applied, but I think it's overall positive in its own right, and
    allowing paginated notes to work is a big plus too.
    b8ce7d1c
notes_controller_spec.rb 30.5 KB