Thank you, Azion, I have solved this problem, The reason why the query speed is too slow is mainly that the server where the program is located is too far away from the server where the database is located. My backend program is deployed in China, the database is deployed in the US, and every query will establish a connection, so the query speed is slow.
On Monday, September 10, 2018, at 7:30:19 PM UTC+8, Azion wrote: > > Hi Haitao, > > Are you sure it's the serialization the problem? Asking this 'cause, if > your database/model doesn't have an index over `eth_tx_hash`, it may take a > very long time for the database to find the records you need. > > (Also, maybe using `.select_related()` ( > https://docs.djangoproject.com/en/2.1/ref/models/querysets/#select-related) > on your query may speed things up by bringing all related elements, in case > your model have a few ForeignKeys or ManyToManyFields). > > On Mon, Sep 10, 2018 at 6:30 AM, [email protected] <javascript:> wrote: > > record = ExchangeCoinTransaction.objects.filter(eth_tx_hash=eth_tx_hash) > if not record: > return False, "the eth transaction is't exchange coin transaction" > json_rec = serializers.serialize("json", record) > record = json.loads(json_rec) > > #This simple query database, and serialize the results of the operation > takes 3 to 4s, similar operations may take more time > > -- > You received this message because you are subscribed to the Google Groups > "Django REST framework" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] <javascript:>. > For more options, visit https://groups.google.com/d/optout. > > -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
