Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit61fba84

Browse files
author
Gauvain Pocentek
committed
Add laziness to get()
The goal is to create empty objects (no API called) but give access tothe managers. Using this users can reduce the number of API calls butstill use the same API to access children objects.For example the following will only make one API call but will still getthe result right:gl.projects.get(49, lazy=True).issues.get(2, lazy=True).notes.list()This removes the need for more complex managers attributes (e.g.gl.project_issue_notes)
1 parent197ffd7 commit61fba84

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

‎gitlab/mixins.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121

2222

2323
classGetMixin(object):
24-
defget(self,id,**kwargs):
24+
defget(self,id,lazy=False,**kwargs):
2525
"""Retrieve a single object.
2626
2727
Args:
2828
id (int or str): ID of the object to retrieve
29+
lazy (bool): If True, don't request the server, but create a
30+
shallow object giving access to the managers. This is
31+
useful if you want to avoid useless calls to the API.
2932
**kwargs: Extra data to send to the Gitlab server (e.g. sudo)
3033
3134
Returns:
@@ -35,6 +38,9 @@ def get(self, id, **kwargs):
3538
GitlabGetError: If the server cannot perform the request.
3639
"""
3740
path='%s/%s'% (self.path,id)
41+
iflazyisTrue:
42+
returnself._obj_cls(self, {self._obj_cls._id_attr:id})
43+
3844
server_data=self.gitlab.http_get(path,**kwargs)
3945
returnself._obj_cls(self,server_data)
4046

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp