Beispiel #1
0
    def get_all_bank_members_page(
        self,
        bank_id: str,
        content_type=t.Type[ContentType],
        exclusive_start_key: t.Optional[DynamoDBCursorKey] = None,
    ) -> PaginatedResponse[BankMember]:
        PAGE_SIZE = 100
        expected_pk = BankMember.get_pk(bank_id=bank_id,
                                        content_type=content_type)

        if not exclusive_start_key:
            result = self._table.query(
                ScanIndexForward=False,
                KeyConditionExpression=Key("PK").eq(expected_pk),
                FilterExpression=Key("IsRemoved").eq(False),
                Limit=PAGE_SIZE,
            )
        else:
            result = self._table.query(
                ScanIndexForward=False,
                KeyConditionExpression=Key("PK").eq(expected_pk),
                FilterExpression=Key("IsRemoved").eq(False),
                ExclusiveStartKey=exclusive_start_key,
                Limit=PAGE_SIZE,
            )

        return PaginatedResponse(
            t.cast(DynamoDBCursorKey, result.get("LastEvaluatedKey", None)),
            [
                BankMember.from_dynamodb_item(
                    item, signal_type_mapping=self._signal_type_mapping)
                for item in result["Items"]
            ],
        )
Beispiel #2
0
 def get_bank_member_signals_to_process_page(
     self,
     signal_type: t.Type[SignalType],
     exclusive_start_key: t.Optional[DynamoDBCursorKey] = None,
     limit: int = 100,
 ) -> PaginatedResponse[BankMemberSignal]:
     if not exclusive_start_key:
         result = self._table.query(
             IndexName=BankMemberSignal.BANK_MEMBER_SIGNAL_CURSOR_INDEX,
             ScanIndexForward=True,
             KeyConditionExpression=Key(
                 BankMemberSignal.
                 BANK_MEMBER_SIGNAL_CURSOR_INDEX_SIGNAL_TYPE).eq(
                     signal_type.get_name()),
             Limit=limit,
         )
     else:
         result = self._table.query(
             IndexName=BankMemberSignal.BANK_MEMBER_SIGNAL_CURSOR_INDEX,
             ScanIndexForward=True,
             KeyConditionExpression=Key(
                 BankMemberSignal.
                 BANK_MEMBER_SIGNAL_CURSOR_INDEX_SIGNAL_TYPE).eq(
                     signal_type.get_name()),
             ExclusiveStartKey=exclusive_start_key,
             Limit=limit,
         )
     return PaginatedResponse(
         t.cast(DynamoDBCursorKey, result.get("LastEvaluatedKey", None)),
         [
             BankMemberSignal.from_dynamodb_item(
                 item, signal_type_mapping=self._signal_type_mapping)
             for item in result["Items"]
         ],
     )
Beispiel #3
0
    def get_recent_items_page(
        cls, table: Table, exclusive_start_key: t.Optional[DynamoDBCursorKey] = None
    ) -> PaginatedResponse["MatchRecord"]:
        """
        Get a paginated list of recent match records. Subsequent calls must use
        `return_value.last_evaluated_key`.
        """
        if not exclusive_start_key:
            # Evidently, https://github.com/boto/boto3/issues/2813 boto is able
            # to distinguish fun(Parameter=None) from fun(). So, we can't use
            # exclusive_start_key's optionality. We have to do an if clause!
            # Fun!
            result = table.query(
                IndexName="GSI-2",
                Limit=100,
                ScanIndexForward=False,
                KeyConditionExpression=Key("GSI2-PK").eq(
                    DynamoDBItem.get_dynamodb_type_key(cls.__name__)
                ),
            )
        else:
            result = table.query(
                IndexName="GSI-2",
                Limit=100,
                ExclusiveStartKey=exclusive_start_key,
                ScanIndexForward=False,
                KeyConditionExpression=Key("GSI2-PK").eq(
                    DynamoDBItem.get_dynamodb_type_key(cls.__name__)
                ),
            )

        return PaginatedResponse(
            t.cast(DynamoDBCursorKey, result.get("LastEvaluatedKey", None)),
            cls._result_items_to_records(result["Items"]),
        )