Skip to content

Commit

Permalink
Port name_pattern, count, lastid in ProjectResource.getProjects
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyama committed Jan 24, 2022
1 parent e999615 commit a9cda61
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ public DatabaseProjectStore(int siteId)

@DigdagTimed(value = "dpst_", category = "db", appendMethodName = true)
@Override
public List<StoredProjectWithRevision> getProjectsWithLatestRevision(int pageSize, Optional<Integer> lastId, AccessController.ListFilter acFilter)
public List<StoredProjectWithRevision> getProjectsWithLatestRevision(int pageSize, Optional<Integer> lastId, Optional<String> namePattern, AccessController.ListFilter acFilter)
{
return autoCommit((handle, dao) -> dao.getProjectsWithLatestRevision(siteId, pageSize, lastId.or(0), acFilter.getSql()));
return autoCommit((handle, dao) -> dao.getProjectsWithLatestRevision(siteId, pageSize, lastId.or(0), generatePartialMatchPattern(namePattern), acFilter.getSql()));
}

@DigdagTimed(value = "dpst_", category = "db", appendMethodName = true)
Expand Down Expand Up @@ -584,7 +584,12 @@ public interface H2Dao
" and proj.id > :lastId" +
" order by proj.id asc" +
" limit :limit")
List<StoredProjectWithRevision> getProjectsWithLatestRevision(@Bind("siteId") int siteId, @Bind("limit") int limit, @Bind("lastId") int lastId, @Define("acFilter") String acFilter);
List<StoredProjectWithRevision> getProjectsWithLatestRevision(
@Bind("siteId") int siteId,
@Bind("limit") int limit,
@Bind("lastId") int lastId,
@Bind("namePattern") String namePattern,
@Define("acFilter") String acFilter);

// h2's MERGE doesn't return generated id when conflicting row already exists
@SqlUpdate("merge into projects" +
Expand Down Expand Up @@ -647,7 +652,12 @@ public interface PgDao
" where projects_with_revision.revision_id = projects_with_revision.max_revision_id" +
" order by id asc" +
" limit :limit")
List<StoredProjectWithRevision> getProjectsWithLatestRevision(@Bind("siteId") int siteId, @Bind("limit") int limit, @Bind("lastId") int lastId, @Define("acFilter") String acFilter);
List<StoredProjectWithRevision> getProjectsWithLatestRevision(
@Bind("siteId") int siteId,
@Bind("limit") int limit,
@Bind("lastId") int lastId,
@Bind("namePattern") String namePattern,
@Define("acFilter") String acFilter);

@SqlQuery("insert into projects" +
" (site_id, name, created_at)" +
Expand Down Expand Up @@ -716,7 +726,12 @@ List<StoredProject> getProjects(
@Bind("namePattern") String namePattern,
@Define("acFilter") String acFilter);

List<StoredProjectWithRevision> getProjectsWithLatestRevision(@Bind("siteId") int siteId, @Bind("limit") int limit, @Bind("lastId") int lastId, @Define("acFilter") String acFilter);
List<StoredProjectWithRevision> getProjectsWithLatestRevision(
@Bind("siteId") int siteId,
@Bind("limit") int limit,
@Bind("lastId") int lastId,
@Bind("namePattern") String namePattern,
@Define("acFilter") String acFilter);

@SqlUpdate("update projects" +
" set deleted_name = name, deleted_at = now(), name = NULL" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface ProjectStore
{
List<StoredProject> getProjects(int pageSize, Optional<Integer> lastId, Optional<String> namePattern, AccessController.ListFilter acFilter);

List<StoredProjectWithRevision> getProjectsWithLatestRevision(int pageSize, Optional<Integer> lastId, AccessController.ListFilter acFilter);
List<StoredProjectWithRevision> getProjectsWithLatestRevision(int pageSize, Optional<Integer> lastId, Optional<String> namePattern, AccessController.ListFilter acFilter);

ProjectMap getProjectsByIdList(List<Integer> projIdList);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ public void testGetAndNotFounds()
assertEquals(ImmutableList.of(proj2), store.getProjects(100, Optional.of(proj1.getId()), Optional.absent(), () -> "true"));
assertEmpty(anotherSite.getProjects(100, Optional.absent(), Optional.absent(), () -> "true"));

assertEquals(ImmutableList.of(proj1Rev1, proj2Rev3), store.getProjectsWithLatestRevision(100, Optional.absent(), () -> "true"));
assertEquals(ImmutableList.of(proj1Rev1), store.getProjectsWithLatestRevision(1, Optional.absent(), () -> "true"));
assertEquals(ImmutableList.of(proj2Rev3), store.getProjectsWithLatestRevision(100, Optional.of(proj1.getId()), () -> "true"));
assertEmpty(anotherSite.getProjectsWithLatestRevision(100, Optional.absent(), () -> "true"));
assertEquals(ImmutableList.of(proj1Rev1, proj2Rev3), store.getProjectsWithLatestRevision(100, Optional.absent(), Optional.absent(), () -> "true"));
assertEquals(ImmutableList.of(proj1Rev1), store.getProjectsWithLatestRevision(1, Optional.absent(), Optional.absent(), () -> "true"));
assertEquals(ImmutableList.of(proj2Rev3), store.getProjectsWithLatestRevision(100, Optional.of(proj1.getId()), Optional.absent(), () -> "true"));
assertEmpty(anotherSite.getProjectsWithLatestRevision(100, Optional.absent(), Optional.absent(), () -> "true"));

assertEquals(ImmutableList.of(rev3, rev2), store.getRevisions(proj2.getId(), 100, Optional.absent())); // revision is returned in reverse order
assertEquals(ImmutableList.of(rev3), store.getRevisions(proj2.getId(), 1, Optional.absent()));
Expand Down Expand Up @@ -432,7 +432,7 @@ public void testDeleteProject()

// listing doesn't include deleted projects
assertEquals(ImmutableList.of(), store.getProjects(100, Optional.absent(), Optional.absent(), () -> "true"));
assertEquals(ImmutableList.of(), store.getProjectsWithLatestRevision(100, Optional.absent(), () -> "true"));
assertEquals(ImmutableList.of(), store.getProjectsWithLatestRevision(100, Optional.absent(), Optional.absent(), () -> "true"));
assertEquals(ImmutableList.of(), store.getLatestActiveWorkflowDefinitions(100, Optional.absent(), Optional.absent(), () -> "true"));

// lookup by project/revision id succeeds and deletedAt is set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ public RestProjectCollection getProjects(
siteTarget,
getAuthenticatedUser());

collection = ps.getProjectsWithLatestRevision(100, Optional.absent(),
collection = ps.getProjectsWithLatestRevision(
Optional.fromNullable(count).or(100),
Optional.fromNullable(lastId),
Optional.fromNullable(namePattern),
ac.getListProjectsFilterOfSite(siteTarget, getAuthenticatedUser()))
.stream()
.map(projWithRev -> {
Expand Down

0 comments on commit a9cda61

Please sign in to comment.