Skip to content

Commit 64cdfa7

Browse files
committed
Merge remote-tracking branch 'origin/dev' into dev
# Conflicts: # CHANGELOG.md
2 parents 16fdf5c + 94d38a6 commit 64cdfa7

11 files changed

+41
-98
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### 0.1.5
66

7+
- Remove `byte2int` and `int2byte`.
78
- Fix warning for sql_mode.
89

910
### 0.1.4

asyncmy/replication/events.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import binascii
22
import struct
33

4-
from asyncmy.replication.utils import byte2int, int2byte
5-
64

75
class BinLogEvent:
86
def __init__(
@@ -37,7 +35,7 @@ def processed(self):
3735
def _read_table_id(self):
3836
# Table ID is 6 byte
3937
# pad little-endian number
40-
table_id = self.packet.read(6) + int2byte(0) + int2byte(0)
38+
table_id = self.packet.read(6) + bytes(0) + bytes(0)
4139
return struct.unpack("<Q", table_id)[0]
4240

4341
async def init(self):
@@ -52,7 +50,7 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs)
5250
from_packet, event_size, table_map, ctl_connection, **kwargs
5351
)
5452

55-
self.commit_flag = byte2int(self.packet.read(1)) == 1
53+
self.commit_flag = self.packet.read(1) == 1
5654
self.sid = self.packet.read(16)
5755
self.gno = struct.unpack("<Q", self.packet.read(8))[0]
5856

@@ -129,7 +127,7 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs)
129127
# Post-header
130128
self.slave_proxy_id = self.packet.read_uint32()
131129
self.execution_time = self.packet.read_uint32()
132-
self.schema_length = byte2int(self.packet.read(1))
130+
self.schema_length = self.packet.read(1)
133131
self.error_code = self.packet.read_uint16()
134132
self.status_vars_length = self.packet.read_uint16()
135133

asyncmy/replication/packets.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
WRITE_ROWS_EVENT_V2,
4949
XID_EVENT,
5050
)
51-
from asyncmy.replication.utils import byte2int
5251

5352

5453
class BinLogPacket:
@@ -104,7 +103,7 @@ def __init__(
104103

105104
# Header
106105
self.timestamp = unpack[1]
107-
self.event_type = byte2int(unpack[2])
106+
self.event_type = unpack[2]
108107
self.server_id = unpack[3]
109108
self.event_size = unpack[4]
110109
# position of the next event
@@ -167,7 +166,7 @@ def advance(self, size):
167166
self._packet.advance(size)
168167

169168
def read_length_coded_binary(self):
170-
c = byte2int(self.read(1))
169+
c = self.read(1)
171170
if c == NULL_COLUMN:
172171
return None
173172
if c < UNSIGNED_CHAR_COLUMN:

asyncmy/replication/row_events.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
from .errors import TableMetadataUnavailableError
4141
from .events import BinLogEvent
4242
from .table import Table
43-
from .utils import byte2int
4443

4544

4645
class RowsEvent(BinLogEvent):
@@ -540,10 +539,10 @@ def __init__(self, from_packet, event_size, table_map, connection, **kwargs):
540539
self.flags = struct.unpack("<H", self.packet.read(2))[0]
541540

542541
# Payload
543-
self.schema_length = byte2int(self.packet.read(1))
542+
self.schema_length = self.packet.read(1)
544543
self.schema = self.packet.read(self.schema_length).decode()
545544
self.packet.advance(1)
546-
self.table_length = byte2int(self.packet.read(1))
545+
self.table_length = self.packet.read(1)
547546
self.table_name = self.packet.read(self.table_length).decode()
548547
schema_table = f"{self.schema}.{self.table_name}"
549548
if self._only_tables is not None and schema_table not in self._only_tables:
@@ -606,7 +605,7 @@ async def init(self):
606605
"COLUMN_TYPE": "BLOB", # we don't know what it is, so let's not do anything with it.
607606
"COLUMN_KEY": "",
608607
}
609-
col = Column(byte2int(column_type), column_schema, self.packet)
608+
col = Column(column_type, column_schema, self.packet)
610609
self.columns.append(col)
611610

612611
self._table = Table(

asyncmy/replication/utils.py

-12
This file was deleted.

benchmark/__init__.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import faker
21
import MySQLdb
32
import pymysql
43

@@ -8,15 +7,14 @@
87
conn_mysqlclient = MySQLdb.connect(**connection_kwargs)
98
conn_pymysql = pymysql.connect(**connection_kwargs)
109
COUNT = 50000
11-
faker = faker.Faker()
1210

1311
data = [
1412
(
1513
1,
16-
faker.date_time().date(),
17-
faker.date_time(),
14+
"2021-01-01",
15+
"2020-07-16 22:49:54",
1816
1,
19-
faker.name(),
17+
"asyncmy",
2018
1,
2119
)
2220
for _ in range(COUNT)

benchmark/benchmark_delete.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
from benchmark import COUNT, connection_kwargs
99
from benchmark.decorators import cleanup, fill_data
1010

11+
count = int(COUNT / 5)
12+
1113

1214
@cleanup
1315
@fill_data
1416
async def delete_asyncmy():
1517
conn = await asyncmy.connect(**connection_kwargs)
1618
async with conn.cursor() as cur:
1719
t = time.time()
18-
for i in range(COUNT):
20+
for i in range(count):
1921
ret = await cur.execute("delete from test.asyncmy where `id`=%s", (i + 1,))
2022
assert ret == 1
2123
return time.time() - t
@@ -27,7 +29,7 @@ async def delete_aiomysql():
2729
conn = await aiomysql.connect(**connection_kwargs)
2830
async with conn.cursor() as cur:
2931
t = time.time()
30-
for i in range(COUNT):
32+
for i in range(count):
3133
ret = await cur.execute("delete from test.asyncmy where `id`=%s", (i + 1,))
3234
assert ret == 1
3335
return time.time() - t
@@ -39,7 +41,7 @@ def delete_mysqlclient():
3941
conn = MySQLdb.connect(**connection_kwargs)
4042
cur = conn.cursor()
4143
t = time.time()
42-
for i in range(COUNT):
44+
for i in range(count):
4345
ret = cur.execute("delete from test.asyncmy where `id`=%s", (i + 1,))
4446
assert ret == 1
4547
return time.time() - t
@@ -51,7 +53,7 @@ def delete_pymysql():
5153
conn = pymysql.connect(**connection_kwargs)
5254
cur = conn.cursor()
5355
t = time.time()
54-
for i in range(COUNT):
56+
for i in range(count):
5557
ret = cur.execute("delete from test.asyncmy where `id`=%s", (i + 1,))
5658
assert ret == 1
5759
return time.time() - t

benchmark/benchmark_update.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
from benchmark import COUNT, connection_kwargs
99
from benchmark.decorators import cleanup, fill_data
1010

11+
count = int(COUNT / 5)
12+
1113

1214
@cleanup
1315
@fill_data
1416
async def update_asyncmy():
1517
conn = await asyncmy.connect(**connection_kwargs)
1618
async with conn.cursor() as cur:
1719
t = time.time()
18-
for i in range(COUNT):
20+
for i in range(count):
1921
await cur.execute(
2022
"update test.asyncmy set `string`=%s where `id` = %s",
2123
(
@@ -32,7 +34,7 @@ async def update_aiomysql():
3234
conn = await aiomysql.connect(**connection_kwargs)
3335
async with conn.cursor() as cur:
3436
t = time.time()
35-
for i in range(COUNT):
37+
for i in range(count):
3638
await cur.execute(
3739
"update test.asyncmy set `string`=%s where `id` = %s",
3840
(
@@ -49,7 +51,7 @@ def update_mysqlclient():
4951
conn = MySQLdb.connect(**connection_kwargs)
5052
cur = conn.cursor()
5153
t = time.time()
52-
for i in range(COUNT):
54+
for i in range(count):
5355
cur.execute(
5456
"update test.asyncmy set `string`=%s where `id` = %s",
5557
(
@@ -66,7 +68,7 @@ def update_pymysql():
6668
conn = pymysql.connect(**connection_kwargs)
6769
cur = conn.cursor()
6870
t = time.time()
69-
for i in range(COUNT):
71+
for i in range(count):
7072
cur.execute(
7173
"update test.asyncmy set `string`=%s where `id` = %s",
7274
(

benchmark/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
`string` varchar(200) DEFAULT NULL,
4545
`tinyint` tinyint DEFAULT NULL,
4646
PRIMARY KEY (`id`)
47-
) ENGINE=InnoDB AUTO_INCREMENT=400001 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"""
47+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"""
4848
)
4949
cur.execute("truncate table test.asyncmy")
5050

0 commit comments

Comments
 (0)