Skip to content

Commit

Permalink
decreased timeout for retries, fixed encoding, show source as alter f…
Browse files Browse the repository at this point in the history
…or unavailable images
  • Loading branch information
ar0ne committed Dec 11, 2023
1 parent be3024f commit a02bd16
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bgd/services/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

log = logging.getLogger(__name__)

STREAM_RETRY_TIMEOUT = 30000 # milliseconds
STREAM_RETRY_TIMEOUT = 600 # milliseconds


class GameInfoService(ABC):
Expand Down
12 changes: 10 additions & 2 deletions bgd/utils.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
"""
App utilities.
"""
import logging
from typing import Any

import orjson
from fastapi.encoders import jsonable_encoder
from fastapi_cache import Coder

log = logging.getLogger(__name__)


# pylint: disable=no-member
class ORJsonCoder(Coder):
"""orjson coder"""

@classmethod
def encode(cls, value: Any) -> str:
"""serialize python object to json-bytes"""
return str(orjson.dumps(value, default=jsonable_encoder)) # pylint: disable=no-member
return orjson.dumps(value, default=jsonable_encoder).decode("utf-8")

@classmethod
def decode(cls, value: Any) -> Any:
"""deserializes JSON to Python objects"""
return orjson.loads(value) # pylint: disable=no-member
try:
return orjson.loads(value)
except orjson.JSONDecodeError:
log.warning("Unable to decode %s", value)
return None
2 changes: 1 addition & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ <h5 class="card-title>">
</div>
</div>
<div v-if="result.images" class="col-md-1">
<img v-bind:src="result.images[0]" alt="Search result image" class="rounded img-thumbnail float-left">
<img v-bind:src="result.images[0]" v-bind:alt="result.source" class="rounded img-thumbnail float-left">
</div>
</div>
</div>
Expand Down

0 comments on commit a02bd16

Please sign in to comment.