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

Support pagination in sessions listing API #1173

Closed
wants to merge 27 commits into from

Conversation

tosametal
Copy link
Contributor

@tosametal tosametal commented Jul 11, 2019

Support pagination on WorkflowsPage, ProjectsPage and ProjectPage(#1106 is related)

I made the docker image, so you can check the ui with the following command.

docker pull tosametal/digdag-pagination:0.0.1
docker run -d -p 65432:65432 tosametal/digdag-pagination:0.0.1

→ access to http://localhost:65432

@yoyama yoyama self-requested a review July 12, 2019 04:50
@tosametal
Copy link
Contributor Author

tosametal commented Jul 12, 2019

I also created an image to show the loading when fetching sessions.
tosametal/digdag-pagination:loading3

Please check this too and compare which looks better.

@hiroyuki-sato
Copy link
Contributor

Hello, @tosametal

Thank you for creating this PR.

Does the difference between tosametal/digdag-pagination:loading3 and
tosametal/digdag-pagination:0.0.1 is that whether show loading image or not?

If so, I like Loading version.

I confirmed the following steps.

no loading version

docker pull tosametal/digdag-pagination:0.0.1
docker run -d -p 65432:65432 tosametal/digdag-pagination:0.0.1
digdag init -t sh fuga
cd fuga
digdag push fuga

# macOS
for i in `seq 0 120` ; do
  d=`date -v+${i}d -j -f "%Y-%m-%d" "2019-01-01" +"%Y-%m-%d"` 
  digdag start fuga fuga --session $d  
done

スクリーンショット 2019-07-12 18 04 20

Loading version

docker pull tosametal/digdag-pagination:loading3
docker run -d -p 65432:65432 tosametal/digdag-pagination:loading3
digdag init -t sh fuga
cd fuga
digdag push fuga

# macOS
for i in `seq 0 120` ; do
  d=`date -v+${i}d -j -f "%Y-%m-%d" "2019-01-01" +"%Y-%m-%d"` 
  digdag start fuga fuga --session $d  
done

スクリーンショット 2019-07-12 18 12 42
スクリーンショット 2019-07-12 18 12 31

@tosametal
Copy link
Contributor Author

@hiroyuki-sato Thank you for confirmation.

Does the difference between tosametal/digdag-pagination:loading3 and
tosametal/digdag-pagination:0.0.1 is that whether show loading image or not?

Yes, that's the only difference.

If so, I like Loading version.

OK. I will add a commit that shows the loading image to this PR.

When the number of pages is more than 10, the button display changes. Please try it.

@hiroyuki-sato
Copy link
Contributor

Hello, @tosametal

This is just my(not committer) opinion.

What do you think? @yoyama, @muga, and @szyn?

@hiroyuki-sato
Copy link
Contributor

Hello, @tosametal

When the number of pages is more than 10, the button display changes. Please try it.

It seems to work well.

docker pull tosametal/digdag-pagination:loading3
docker run -d -p 65432:65432 tosametal/digdag-pagination:loading3
digdag init -t sh fuga
cd fuga
digdag push fuga

# macOS
for i in `seq 0 1100` ; do
  d=`date -v+${i}d -j -f "%Y-%m-%d" "2016-01-01" +"%Y-%m-%d"` 
  digdag start fuga fuga --session $d  
done

スクリーンショット 2019-07-16 17 03 22

Copy link
Contributor

@yoyama yoyama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR. I took a brief look.
Please check the comments.
Current implementation will cause problem in large use case.
In addition please take care of API compatibility, method signature of common classes as much as possible.

@yoyama
Copy link
Contributor

yoyama commented Jul 16, 2019

In addition I propose split this ticket to UI part and API part for our review.

@tosametal
Copy link
Contributor Author

@hiroyuki-sato Thank you for confirmation. I confirmed it as follows.

# sample1.dig
timezone: 'Asia/Tokyo'
schedule:
  minutes_interval>: 1
+task:
  sh>: echo hoge
for i in `seq 2 100`
do
  cp sample1.dig sample$i.dig
done
digdag push project -e http://localhost:65432

and wait 10 minutes...

@tosametal
Copy link
Contributor Author

@yoyama Thank you for your review. I will check the comments and fix them.

In addition I propose split this ticket to UI part and API part for our review.

Does this mean I should close this PR and create two new PRs?

@yoyama
Copy link
Contributor

yoyama commented Jul 17, 2019

@tosametal You don't need to close this PR.
I suppose that remove UI codes from this PR and then create follow up PR which include UI code.
How about this way?

@tosametal
Copy link
Contributor Author

@yoyama I agree with your suggestion.I will do that.

@yoyama
Copy link
Contributor

yoyama commented Jul 31, 2019

@tosametal If you finished update, please ping me.

@tosametal
Copy link
Contributor Author

@yoyama I checked your comments, and fix the code.Please check the commits below.

ff63080
2fecfdf

@yoyama
Copy link
Contributor

yoyama commented Sep 3, 2019

@tosametal Thanks for you fix. I will check it later.

@yoyama yoyama changed the title Support pagination in projects and sessions listing API Support pagination in sessions listing API Sep 3, 2019
@yoyama
Copy link
Contributor

yoyama commented Sep 3, 2019

I updated the title. I misunderstood this PR.
This PR try to add page_number parameter to '/api/sessions/{id}' and '/api/projects/{id}/sessions'.
Both are list of sessions.


return RestModels.sessionCollection(rs, sessions);
Integer page = Optional.fromNullable(pageNumber).or(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name page is uncertain.
It may be better to define QueryParamValidator.validatePageNumber and change the name to validPageNumber.

@@ -64,17 +65,20 @@ public SessionResource(
@Path("/api/sessions")
public RestSessionCollection getSessions(
@QueryParam("last_id") Long lastId,
@QueryParam("page_size") Integer pageSize)
@QueryParam("page_size") Integer pageSize,
@QueryParam("page_number") Integer pageNumber)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed if page_number <=0, API become error in SQL execution.
I guess it is better to validate before execute query.
But page_size is also same behavior.
It is not mandatory and another PR which fix both page_size and page_number may be better.

Copy link
Contributor Author

@tosametal tosametal Sep 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will fix the problem in another PR.

@@ -425,15 +427,18 @@ public RestSessionCollection getSessions(
SessionStore ss = ssm.getSessionStore(getSiteId());

StoredProject proj = ensureNotDeletedProject(ps.getProjectById(projectId));
Integer page = Optional.fromNullable(pageNumber).or(1);
Copy link
Contributor

@yoyama yoyama Sep 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as SessionResource. Please change var name.

}

@Override
public Integer getTotalSessionsCount(Optional<Long> lastId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getSessionsCount may be better name.

}

@Override
public Integer getTotalProjectSessionsCount(Optional<Long> lastId, int projectId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getSessionsCountOfProject may be better to fit getSessionsOfProject.

@tosametal
Copy link
Contributor Author

@yoyama I added validatePageNumber to QueryParamValidator and fixed variable and method name.Please check it.

@yoyama
Copy link
Contributor

yoyama commented Sep 30, 2019

@tosametal Sorry for my late response.
I just started to review your latest PR.
Please wait for a moment.
Your PR is large, so I need to check carefully.

}

@Override
public List<StoredSessionWithLastAttempt> getSessions(int pageSize, Optional<Long> lastId, int pageNumber)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess switch the order of pageNumber and lastId may be understandable.
Other method also same.

" join session_attempts sa on sa.id = s.last_attempt_id" +
" where s.project_id = :projectId" +
" and s.id < :lastId")
Integer getSessionsCountOfProject(@Bind("lastId") long lastId, @Bind("projectId") int projectId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this query is different from getSessionsOfProject. Not have site_id condition.
Could you fix it and add test code for *Count() method.
In addition the test data should include different site_id and check.

Copy link
Contributor

@yoyama yoyama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tosametal Sorry for my late response. I made some comments to your code. please check and fix them.

@yoyama yoyama modified the milestones: v0.9.40, v0.9.41 Dec 10, 2019
@tosametal
Copy link
Contributor Author

@yoyama Sorry for my too late response. I fixed the below.Please check them.

  • switch the order of pageNumber and lastId
  • add site_id condition and add test

@yoyama yoyama modified the milestones: v0.9.41, v0.9.42 Jan 21, 2020
@yoyama yoyama modified the milestones: v0.9.42, v0.9.43 Jun 29, 2020
@yoyama
Copy link
Contributor

yoyama commented Dec 11, 2020

@tosametal I would like to close this ticket once because it is too old and code is conflicted and we are working on v0.10.0 release.
In addition if we add these functionality, it is better to support not only sessions but also attempts and other for the integrity of API design.
If you want to continue, feel free to reopen after v0.10.0 released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants