Skip to content

Instantly share code, notes, and snippets.

View erwan-lemonnier's full-sized avatar

Erwan erwan-lemonnier

View GitHub Profile
@erwan-lemonnier
erwan-lemonnier / message.json
Last active November 28, 2020 03:33
A basic message structure in a chat
{
"message_id": "1234567890",
"chat_id": "chat-123",
"author_id": "user-456",
"text": "this is a message",
"date_created": "2020-11-28 13:15:09+00:00"
}
@erwan-lemonnier
erwan-lemonnier / cache_and_saver_pattern.py
Last active November 1, 2020 06:17
Bulk fetch from Datastore only if objects aren't already in the cache
# Here is a more complicated endpoint that retrieve objects
# from datastore in multiple phases, and build up a queue of objects
# to bulk commit at the end
from pymacaron.auth import get_userid
def do_get_recommended_new_friends(data):
cache = ObjectCache()
saver = ObjectSaver(cache=cache)
@erwan-lemonnier
erwan-lemonnier / do_add_friend.py
Last active November 1, 2020 06:31
Bulk operation via a smart cache (proof of concept)
from pymacaron.auth import get_userid
# Implements an hypothetical endpoint that let's a user (identified by a JWT token)
# add another user as friend (identified by its user ID in the data object received
# as parameter, mapping to the POST request's body)
def do_add_friend(data):
viewer_id = get_userid() # Extract the ID of the current user from its JWT auth token
friend_id = data.user_id # And 'user_id' in the POST request is the friend's ID