original_docstring: 
          Returns a page of results based on the cursor query string parameter. Designed to make the
          last page empty
          
docstring: Returns a page of results based on the cursor query string parameter. Designed to make the
  last page empty
docstring_tokens: Returns a page of results based on the cursor query string parameter . Designed to make the last page empty
code: def paginate_queryset(self, queryset, request, view=None):
          """
          Returns a page of results based on the cursor query string parameter. Designed to make the
          last page empty
          """
          # Extract cursor from query string. Inclues partial support for DRF's base64-encoded cursor
          # of timestamp + offset, the previous pagination mechanism. This is so that at the time
          # of deployment the Activity Stream can carry on from at most a few pages before where it
          # was. Once this is live and working, the DRF support can be removed
          try:
              after_ts_str = parse_qs(b64decode(request.GET.getlist('cursor')[0]))[b'p'][0].decode()
              after_id_str = '00000000-0000-0000-0000-000000000000'
          except (IndexError, KeyError, binascii.Error):
              after_ts_str, after_id_str = request.GET.getlist(
                  'cursor',
                  ('0001-01-01 00:00:00.000000+00:00', '00000000-0000-0000-0000-000000000000'),
              )
  
          after_ts = datetime.fromisoformat(after_ts_str)
          after_id = uuid.UUID(after_id_str)
  
          # Filter queryset to be after cursor.
          #
          # A composite/row/tuple lexicographic comparison is used to have the biggest chance of
          # fully using a multicolumn index. When tested on interactions in production, these queries
          # take ~50ms. If doing the comparison "manually", such queries take take ~1.5s+
          #
          # To do this in the Django ORM requires 'annotate', which itself requires a small hack: the
          # setting of an output_field, which can be anything since we don't access the value.
          modified_on_id = Func(F('modified_on'), F('id'), function='ROW', output_field=TextField())
          after_ts_id = Func(after_ts, after_id, function='ROW')
  
          # Mitigate the risk of timestamps being committed slightly out of order, which could result
          # in activities being missed when the last page is polled
          one_second_ago = datetime.now() - timedelta(seconds=1)
  
          page = list(queryset
                      .annotate(modified_on_id=modified_on_id)
                      .filter(modified_on_id__gt=after_ts_id, modified_on__lt=one_second_ago)
                      # Do not use ROW expressions in order_by: it seems to have an extremely
                      # negative performance impact
                      .order_by('modified_on', 'id')[:self.page_size])
  
          # Build and store next link for all non-empty pages to be used in get_paginated_response
          if not page:
              self.next_link = None
          else:
              final_instance = page[-1]
              next_after_ts_str = final_instance.modified_on.isoformat(timespec='microseconds')
              next_after_id_str = str(final_instance.id)
              self.next_link = self._replace_query_param(
                  request.build_absolute_uri(),
                  'cursor', (next_after_ts_str, next_after_id_str),
              )
  
          return page
code_tokens: def paginate_queryset ( self , queryset , request , view = None ) : try : after_ts_str = parse_qs ( b64decode ( request . GET . getlist ( 'cursor' ) [ 0 ] ) ) [ b'p' ] [ 0 ] . decode ( ) after_id_str = '00000000-0000-0000-0000-000000000000' except ( IndexError , KeyError , binascii . Error ) : after_ts_str , after_id_str = request . GET . getlist ( 'cursor' , ( '0001-01-01 00:00:00.000000+00:00' , '00000000-0000-0000-0000-000000000000' ) , ) after_ts = datetime . fromisoformat ( after_ts_str ) after_id = uuid . UUID ( after_id_str ) modified_on_id = Func ( F ( 'modified_on' ) , F ( 'id' ) , function = 'ROW' , output_field = TextField ( ) ) after_ts_id = Func ( after_ts , after_id , function = 'ROW' ) one_second_ago = datetime . now ( ) - timedelta ( seconds = 1 ) page = list ( queryset . annotate ( modified_on_id = modified_on_id ) . filter ( modified_on_id__gt = after_ts_id , modified_on__lt = one_second_ago ) . order_by ( 'modified_on' , 'id' ) [ : self . page_size ] ) if not page : self . next_link = None else : final_instance = page [ - 1 ] next_after_ts_str = final_instance . modified_on . isoformat ( timespec = 'microseconds' ) next_after_id_str = str ( final_instance . id ) self . next_link = self . _replace_query_param ( request . build_absolute_uri ( ) , 'cursor' , ( next_after_ts_str , next_after_id_str ) , ) return page
short_docstring: Returns a page of results based on the cursor query string parameter.
short_docstring_tokens: Returns a page of results based on the cursor query string parameter .
comment: """
          Returns a page of results based on the cursor query string parameter. Designed to make the
          last page empty
          """$SEP$# Extract cursor from query string. Inclues partial support for DRF's base64-encoded cursor$SEP$# of timestamp + offset, the previous pagination mechanism. This is so that at the time$SEP$# of deployment the Activity Stream can carry on from at most a few pages before where it$SEP$# was. Once this is live and working, the DRF support can be removed$SEP$# Filter queryset to be after cursor.$SEP$#$SEP$# A composite/row/tuple lexicographic comparison is used to have the biggest chance of$SEP$# fully using a multicolumn index. When tested on interactions in production, these queries$SEP$# take ~50ms. If doing the comparison "manually", such queries take take ~1.5s+$SEP$#$SEP$# To do this in the Django ORM requires 'annotate', which itself requires a small hack: the$SEP$# setting of an output_field, which can be anything since we don't access the value.$SEP$# Mitigate the risk of timestamps being committed slightly out of order, which could result$SEP$# in activities being missed when the last page is polled$SEP$# Do not use ROW expressions in order_by: it seems to have an extremely$SEP$# negative performance impact$SEP$# Build and store next link for all non-empty pages to be used in get_paginated_response