Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaczero committed Apr 10, 2024
2 parents 1eef4e1 + ec6a1d1 commit 7606153
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ services:
"*",
]

shm_size: '2gb'

ports:
- ${LISTEN:-80}:8000

Expand Down
11 changes: 8 additions & 3 deletions services/aed_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async def get_intersecting(

@trace
async def _assign_country_codes(aeds: Sequence[AED]) -> None:
aed_ids: tuple[int, ...] = tuple(map(attrgetter('id'), aeds))
aed_ids: set[int] = set(map(attrgetter('id'), aeds))

async with db_write() as session:
for batch in batched(aed_ids, 10_000):
Expand Down Expand Up @@ -221,16 +221,21 @@ async def _update_db_diffs(last_update: float) -> None:
logging.info('Nothing to update')
return

aeds: list[AED] = []
# aeds need to be deduplicated to use ON CONFLICT
id_aed_map: dict[int, AED] = {}
remove_ids: set[int] = set()

for action in actions:
for result in _process_action(action):
if isinstance(result, AED):
aeds.append(result)
prev = id_aed_map.get(result.id)
if prev is None or prev.version < result.version:
id_aed_map[result.id] = result
else:
remove_ids.add(result)

aeds = id_aed_map.values()

async with db_write() as session:
if aeds:
stmt = insert(AED).values(
Expand Down
12 changes: 5 additions & 7 deletions services/photo_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,19 @@ async def get_by_id(id: str, *, check_file: bool = True) -> Photo | None:
@staticmethod
@trace
async def upload(node_id: int, user_id: int, file: UploadFile) -> Photo:
photo = Photo(
node_id=node_id,
user_id=user_id,
)

img = Image.open(file.file)
img = ImageOps.exif_transpose(img)
img = _resize_image(img)
img_bytes = _optimize_quality(img)

await photo.file_path.write_bytes(img_bytes)

async with db_write() as session:
photo = Photo(
node_id=node_id,
user_id=user_id,
)
session.add(photo)

await photo.file_path.write_bytes(img_bytes)
return photo


Expand Down

0 comments on commit 7606153

Please sign in to comment.