Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse last resource from url dispatch table #2586

Closed
asvetlov opened this issue Dec 4, 2017 · 6 comments
Closed

Reuse last resource from url dispatch table #2586

asvetlov opened this issue Dec 4, 2017 · 6 comments
Labels
Milestone

Comments

@asvetlov
Copy link
Member

asvetlov commented Dec 4, 2017

If name and path is the same -- add a route to existing resource instead of creating a new one.

E.g.

router.add_get('/', ...)
router.add_post('/', ...)

should create the single resource if path and name are the same.

It reduces resources table size and boosts url lookup if handlers for the same url is grouped together.

The change is easy, Pull Request is welcome.

@asvetlov asvetlov added good first issue Good for newcomers server labels Dec 4, 2017
@asvetlov asvetlov added this to the 3.0 milestone Dec 4, 2017
@sheb
Copy link
Contributor

sheb commented Dec 12, 2017

I'm working on it

@sheb
Copy link
Contributor

sheb commented Dec 12, 2017

Hmm it's not allowed to add a route with existing path and name as it's already handled by

aiohttp.web_urldispatcher.UrlDispatcher().register_resource(..)

See below

app.router.add_get("/", lambda x: x, name="foo")
app.router.add_post("/", lambda x: x, name="foo")
>>> ValueError: Duplicate 'foo', already handled by <PlainResource 'foo'  /

Should I match only the path ?

@asvetlov
Copy link
Member Author

The feature should check both path and name for last added resource.
If they are matched to added one -- return last item.
All functionality could be done in .add_resource() method.

@sheb
Copy link
Contributor

sheb commented Dec 12, 2017

Ok got it, pull request soon

sheb added a commit to sheb/aiohttp that referenced this issue Dec 12, 2017
Do not create a new resource when adding a route with the same
name and path of an existing resource
sheb added a commit to sheb/aiohttp that referenced this issue Dec 13, 2017
Do not create a new resource when adding a route with the same
name and path of an existing resource
sheb added a commit to sheb/aiohttp that referenced this issue Dec 13, 2017
Do not create a new resource when adding a route with the same
name and path of the last added resource.
asvetlov pushed a commit that referenced this issue Dec 14, 2017
* Avoid to create unnecessary resources (#2586)

Do not create a new resource when adding a route with the same
name and path of the last added resource.

* Add a test for AbstractResource().raw_match()

* PrefixResource().raw_match() should always return False
@asvetlov
Copy link
Member Author

Fixed by #2603

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants