Coder Social home page Coder Social logo

Comments (5)

amitt001 avatar amitt001 commented on May 28, 2024

@Hu1-Li I see where this issue is coming from. Ordering the links by created_at desc and then picking the top link as latest will cause this. As for high load websites with many concurrent requests at a time will have many rows with the same created_at time. Wrong ordering is causing while loop and eventually select queries in MySQL to execute many more times than expected.

This can be fixed by ordering by id instead of created_at in latest_default_link method.

I am bit busy right now, I will fix and test this when I get some time. Would you like to make necessary changes and the above tests and open a PR?

from pygmy.

Hu1-Li avatar Hu1-Li commented on May 28, 2024

OK, I will try.

from pygmy.

Hu1-Li avatar Hu1-Li commented on May 28, 2024

Update:
[USING MYSQL]
In my test on the fixed code, which change ordering from created_at to id, the test comes with A99, then it got stucks. As expect, the next short code should be Baa, as the below line

link_manager.find(short_code=base_str)

it got baa

In Mysql, String compare is case-insensitive, thus, causing the server down ,since it needs to loop a really big cycle, from baa to A99 then starts over and over again.

So when creating table, the field short_code should be

short_code varchar(10) COLLATE utf8_bin DEFAULT NULL,`

In SQLAchemy, This can be achieved by

short_code = Column(Unicode(6, collation="utf8_bin"), unique=True, index=True, default=None)

from pygmy.

Hu1-Li avatar Hu1-Li commented on May 28, 2024

Pull request #17 fixes this problem, As for test, i get no idea how to achieve the test for the above problem @amitt001

// Update
For sqlite, it should be
Column(Unicode(6, collation="BINARY"), unique=True, index=True, default=None)
For mysql, it should be
Column(Unicode(6, collation="utf8_bin"), unique=True, index=True, default=None)

emmmm,

from pygmy.

amitt001 avatar amitt001 commented on May 28, 2024

Fixed in commit: 67260ba

@Hu1-Li Thanks for fixing this bug and contributing 🍰

from pygmy.

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.