Reduce time between download count updates

This commit is contained in:
Nassim Jahnke 2023-01-29 10:52:30 +01:00
parent 64e3d8187a
commit 76b4162eb6
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
6 changed files with 23 additions and 12 deletions

View File

@ -27,7 +27,7 @@ public class HangarConfig {
@NestedConfigurationProperty
public final FakeUserConfig fakeUser;
@NestedConfigurationProperty
public HomepageConfig homepage;
public UpdateTasksConfig updateTasks;
@NestedConfigurationProperty
public ChannelsConfig channels;
@NestedConfigurationProperty
@ -87,9 +87,9 @@ public class HangarConfig {
}
@Autowired
public HangarConfig(final FakeUserConfig fakeUser, final HomepageConfig homepage, final ChannelsConfig channels, final PagesConfig pages, final ProjectsConfig projects, final UserConfig user, final OrganizationsConfig org, final ApiConfig api, final SSOConfig sso, final HangarSecurityConfig security, final QueueConfig queue, final DiscourseConfig discourse, final JobsConfig jobs, final StorageConfig storage, final CorsConfig cors) {
public HangarConfig(final FakeUserConfig fakeUser, final UpdateTasksConfig updateTasks, final ChannelsConfig channels, final PagesConfig pages, final ProjectsConfig projects, final UserConfig user, final OrganizationsConfig org, final ApiConfig api, final SSOConfig sso, final HangarSecurityConfig security, final QueueConfig queue, final DiscourseConfig discourse, final JobsConfig jobs, final StorageConfig storage, final CorsConfig cors) {
this.fakeUser = fakeUser;
this.homepage = homepage;
this.updateTasks = updateTasks;
this.channels = channels;
this.pages = pages;
this.projects = projects;

View File

@ -7,5 +7,9 @@ import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.boot.convert.DurationUnit;
@ConfigurationProperties(prefix = "hangar.homepage")
public record HomepageConfig(@DurationUnit(ChronoUnit.MINUTES) @DefaultValue("10") Duration updateInterval) {
public record UpdateTasksConfig(
@DurationUnit(ChronoUnit.MINUTES) @DefaultValue("10") Duration homepage,
@DurationUnit(ChronoUnit.MINUTES) @DefaultValue("5") Duration versionDownloads,
@DurationUnit(ChronoUnit.MINUTES) @DefaultValue("20") Duration projectViews
) {
}

View File

@ -47,6 +47,6 @@ public interface HangarStatsDAO {
""")
void processStatsMain(@Define String individualTable, @Define String dayTable, @Define String statColumn, @Define boolean withUserId, @Define boolean downloads);
@SqlUpdate("DELETE FROM <table> WHERE processed != 0 AND created_at < now() - '10 days'::INTERVAL")
@SqlUpdate("DELETE FROM <table> WHERE processed != 0 AND created_at < now() - '7 days'::INTERVAL")
void deleteOldIndividual(@Define String table);
}

View File

@ -75,7 +75,8 @@ public class StatService extends HangarComponent {
);
}
private void processStats(final String individualTable, final String dayTable, final String statColumn, final boolean downloads) {
@Transactional
void processStats(final String individualTable, final String dayTable, final String statColumn, final boolean downloads) {
this.hangarStatsDAO.fillStatsUserIdsFromOthers(individualTable);
this.hangarStatsDAO.processStatsMain(individualTable, dayTable, statColumn, true, downloads);
this.hangarStatsDAO.processStatsMain(individualTable, dayTable, statColumn, false, downloads);

View File

@ -18,14 +18,18 @@ public class DbUpdateTask {
this.statService = statService;
}
@Scheduled(fixedRateString = "#{@hangarConfig.homepage.updateInterval.toMillis()}")
@Scheduled(fixedRateString = "#{@hangarConfig.updateTasks.homepage.toMillis()}")
public void refreshHomePage() {
this.projectService.refreshHomeProjects();
}
@Scheduled(fixedRateString = "#{@hangarConfig.homepage.updateInterval.toMillis()}", initialDelay = 1000)
public void updateStats() {
this.statService.processProjectViews();
@Scheduled(fixedRateString = "#{@hangarConfig.updateTasks.versionDownloads.toMillis()}", initialDelay = 1000)
public void updateVersionDownloads() {
this.statService.processVersionDownloads();
}
@Scheduled(fixedRateString = "#{@hangarConfig.updateTasks.projectViews.toMillis()}", initialDelay = 1000)
public void updateProjectViews() {
this.statService.processProjectViews();
}
}

View File

@ -94,8 +94,10 @@ hangar:
image: /images/sponsors/minidigger.png
link: https://benndorf.dev
homepage:
update-interval: 10m
update-tasks:
homepage: 10m
version-downloads: 5m
project-views: 20m
channels:
max-name-len: 15