Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	ldes-fragmentisers/ldes-fragmentisers-common/src/test/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationServiceTest.java
#	ldes-server-admin/pom.xml
#	ldes-server-application/pom.xml
#	ldes-server-domain/pom.xml
#	ldes-server-fetch/ldes-server-fetch-common/pom.xml
#	ldes-server-fetch/ldes-server-fetch-rest/pom.xml
#	ldes-server-fragmentation/ldes-server-fragmentation-common/pom.xml
#	ldes-server-fragmentation/ldes-server-fragmentation-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/entities/UnprocessedView.java
#	ldes-server-fragmentation/ldes-server-fragmentation-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/repository/UnprocessedViewRepository.java
#	ldes-server-fragmentation/ldes-server-fragmentation-geospatial/pom.xml
#	ldes-server-fragmentation/ldes-server-fragmentation-reference/pom.xml
#	ldes-server-fragmentation/ldes-server-fragmentation-timebased-hierarchical/pom.xml
#	ldes-server-fragmentation/ldes-server-pagination/pom.xml
#	ldes-server-fragmentation/pom.xml
#	ldes-server-infra-postgres/pom.xml
#	ldes-server-infra-postgres/postgres-admin-repository/pom.xml
#	ldes-server-infra-postgres/postgres-fetch-repository/pom.xml
#	ldes-server-infra-postgres/postgres-fragmentation-repository/pom.xml
#	ldes-server-infra-postgres/postgres-fragmentation-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/postgres/batch/MemberItemReader.java
#	ldes-server-infra-postgres/postgres-ingest-repository/pom.xml
#	ldes-server-infra-postgres/postgres-liquibase/pom.xml
#	ldes-server-infra-postgres/postgres-liquibase/src/main/resources/db/changelog/3_4_1/master.xml
#	ldes-server-infra-postgres/postgres-liquibase/src/main/resources/db/changelog/master.xml
#	ldes-server-infra-postgres/postgres-pagination-repository/pom.xml
#	ldes-server-ingest/ldes-server-ingest-common/pom.xml
#	ldes-server-ingest/ldes-server-ingest-rest/pom.xml
#	ldes-server-instrumentation/pom.xml
#	ldes-server-integration-test/pom.xml
#	ldes-server-maintenance/ldes-server-compaction/pom.xml
#	ldes-server-maintenance/ldes-server-retention/pom.xml
#	pom.xml
  • Loading branch information
Yalz committed Nov 8, 2024
2 parents 051db75 + 1e32b22 commit 3cdd412
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class MemberItemReaderTest {
false
);
private static final String VIEW_NAME = "by-page";
private static final long COLLECTION_ID = 1;
private static final long BY_PAGE_ID = 2;

@Autowired
private JdbcTemplate jdbcTemplate;
Expand Down Expand Up @@ -84,7 +86,7 @@ void tearDown() {

@Test
void given_EmptyMembersTable_when_ReadNewMembers_then_ReturnNull() throws Exception {
setupStepScope(COLLECTION_NAME, VIEW_NAME);
setupStepScope(COLLECTION_ID, COLLECTION_NAME, BY_PAGE_ID, VIEW_NAME);

final FragmentationMember result = newMemberReader.read();

Expand All @@ -95,7 +97,7 @@ void given_EmptyMembersTable_when_ReadNewMembers_then_ReturnNull() throws Except
@ValueSource(strings = {"fantasy/non-existing", "mobility-hindrances/fantasy-view", "fantasy/by-page"})
void given_AbsentCollectionsAndViews_when_RefragmentMembers_then_ReturnNull(String viewNameAsString) throws Exception {
final ViewName viewName = ViewName.fromString(viewNameAsString);
setupStepScope(viewName.getCollectionName(), viewName.getViewName());
setupStepScope(10, viewName.getCollectionName(), 10, viewName.getViewName());

final FragmentationMember result = newMemberReader.read();

Expand All @@ -105,7 +107,7 @@ void given_AbsentCollectionsAndViews_when_RefragmentMembers_then_ReturnNull(Stri
@Test
void given_MembersPresentInDb_test_ReadNewMembers() throws Exception {
int count = 5;
setupStepScope(COLLECTION_NAME, VIEW_NAME);
setupStepScope(COLLECTION_ID, COLLECTION_NAME, BY_PAGE_ID, VIEW_NAME);
insertMembers(count);

final List<FragmentationMember> readMembers = new ArrayList<>();
Expand All @@ -130,8 +132,10 @@ void given_MembersPresentInDb_test_ReadNewMembers() throws Exception {
.isEqualToIgnoringNanos(START_TIME);
}

private void setupStepScope(String collectionName, String viewName) {
private void setupStepScope(long collectionId, String collectionName, long viewId, String viewName) {
JobParameters jobParameters = new JobParametersBuilder()
.addLong("collectionId", collectionId)
.addLong("viewId", viewId)
.addString("collectionName", collectionName)
.addString("viewName", viewName)
.addLong("collectionId", 1L)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- update current counts
update view_stats vs
set
bucketized_count = (select count(distinct(member_id)) from page_members pm WHERE pm.view_id = vs.view_id),
paginated_count = (select count(distinct(member_id)) from page_members pm WHERE pm.view_id = vs.view_id and pm.page_id is not null)
;

-- fix function to increase view stats count when member bucketized
create or replace function on_page_member_inserted() returns trigger language plpgsql as $$
begin
if ((select count(member_id) from page_members
where view_id = NEW.view_id and member_id = NEW.member_id) = 1) then
update view_stats set bucketized_count = bucketized_count + 1 where view_id = NEW.view_id;
end if;
return null;
end
$$;

-- fix function to increase view stats count when member paginated
create or replace function on_page_member_updating() returns trigger language plpgsql as $$
begin
if (OLD.page_id is null and
NEW.page_id is not null and
((select count(member_id) from page_members
where view_id = NEW.view_id and member_id = NEW.member_id) = 1)) then
update view_stats set paginated_count = paginated_count + 1 where view_id = NEW.view_id;
end if;
return NEW;
end
$$;
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">

<include file="alter-unprocessed-views-view.xml" relativeToChangelogFile="true"/>
<include file="fix_view_stats.sql" relativeToChangelogFile="true" />

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<include file="/db/changelog/3_2_0/master.xml" />
<include file="/db/changelog/3_3_0/master.xml" />
<include file="/db/changelog/3_4_0/master.xml" />
<include file="/db/changelog/3_4_1/master.xml" />
<include file="/db/changelog/3_5_0/master.xml" />

</databaseChangeLog>

0 comments on commit 3cdd412

Please sign in to comment.