Skip to content

Commit 77bd9e2

Browse files
committedDec 7, 2024
Delay create index call
1 parent 4420e3f commit 77bd9e2

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed
 

‎legacy-proxy/proxy.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,21 @@ class Server:
113113
def __init__(self, target):
114114
self.index_name = "main"
115115
self.index_url = target
116+
self.index_created = False
117+
self.create_index_lock = asyncio.Lock()
116118

117119
async def create_index(self):
118-
url = self.index_url + f"/{self.index_name}"
119-
async with self.session.put(url) as resp:
120-
resp.raise_for_status()
120+
if self.index_created:
121+
return
122+
async with self.create_index_lock:
123+
url = self.index_url + f"/{self.index_name}"
124+
async with self.session.put(url) as resp:
125+
resp.raise_for_status()
126+
self.index_created = True
121127

122128
async def serve(self, listen_host, listen_port):
123129
async with aiohttp.ClientSession() as session:
124130
self.session = session
125-
await self.create_index()
126131
server = await asyncio.start_server(
127132
self.handle_connection, listen_host, listen_port
128133
)
@@ -135,6 +140,8 @@ async def handle_connection(self, reader, writer):
135140
proto.index_name = self.index_name
136141
proto.index_url = self.index_url
137142

143+
await self.create_index()
144+
138145
while True:
139146
try:
140147
line = await reader.readuntil(b"\n")

0 commit comments

Comments
 (0)
Failed to load comments.