Giter Site home page Giter Site logo

Comments (6)

hishnash avatar hishnash commented on May 20, 2024 1

DRF does the DB query when you do user_serializer.data not on its __init__ method... the cleanest way to deal with this is to create a method that creates the UserSerializer and returns the .data.

from djangochannelsrestframework.

lautarodapin avatar lautarodapin commented on May 20, 2024 1

@lautarodapin did this work for you?

yes thanks! the easiest way was to decorate a method for serializing the current user

@database_sync_to_async
def current_user(self) -> ReturnDict:
  return UserSerializer(self.scope["user"], many=False).data

from djangochannelsrestframework.

lautarodapin avatar lautarodapin commented on May 20, 2024

DRF does the DB query when you do user_serializer.data not on its __init__ method... the cleanest way to deal with this is to create a method that creates the UserSerializer and returns the .data.

Ok thanks! Will try it

from djangochannelsrestframework.

hishnash avatar hishnash commented on May 20, 2024

@lautarodapin did this work for you?

from djangochannelsrestframework.

lautarodapin avatar lautarodapin commented on May 20, 2024

@hishnash do you have a chat or some other active contact app like slack?

I just realized that this isnt a query search xD

 @chats_messages_handler.groups_for_signal
  def chats_messages_handler(self, instance: Message, **kwargs):
      # this block of code is called very often *DO NOT make DB QUERIES HERE*
      yield f'-chat___________{instance.chat_id}'

  @chats_messages_handler.groups_for_consumer
  def chats_messages_handler(self, chat: int, **kwargs):
      # This is called when you subscribe/unsubscribe
      if chat is not None:
          yield f'-chat___________{chat}'

from djangochannelsrestframework.

hishnash avatar hishnash commented on May 20, 2024

@lautarodapin you can DM me on twitter https://twitter.com/hishnash

from djangochannelsrestframework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.