perf(console): optimize game metric ranking queries
This commit is contained in:
parent
83b61e94dd
commit
f79d460f10
@ -89,13 +89,14 @@ public class CountryDashboardGameMetricServiceImpl implements CountryDashboardGa
|
||||
Long total = countryDashboardDAO.countGamePeriodMetrics(
|
||||
condition.periodType, condition.startTime, condition.endTime,
|
||||
PERIOD_ALL.equals(condition.periodType) ? PERIOD_ALL : null,
|
||||
condition.statTimezone, condition.countryKeyword, countryCodes, gameProvider, gameKeyword,
|
||||
condition.sysOrigin);
|
||||
condition.startPeriodKey, condition.endPeriodKey, condition.statTimezone,
|
||||
condition.countryKeyword, countryCodes, gameProvider, gameKeyword, condition.sysOrigin);
|
||||
List<CountryDashboardGameMetricCO> records = countryDashboardDAO.listGamePeriodMetrics(
|
||||
condition.periodType, condition.startTime, condition.endTime,
|
||||
PERIOD_ALL.equals(condition.periodType) ? PERIOD_ALL : null,
|
||||
condition.statTimezone, condition.countryKeyword, countryCodes, gameProvider, gameKeyword,
|
||||
condition.sysOrigin, sortSpec.column(), sortSpec.direction(), offset, limit)
|
||||
condition.startPeriodKey, condition.endPeriodKey, condition.statTimezone,
|
||||
condition.countryKeyword, countryCodes, gameProvider, gameKeyword, condition.sysOrigin,
|
||||
sortSpec.column(), sortSpec.direction(), offset, limit)
|
||||
.stream()
|
||||
.map(this::toCO)
|
||||
.toList();
|
||||
@ -133,13 +134,14 @@ public class CountryDashboardGameMetricServiceImpl implements CountryDashboardGa
|
||||
Long total = countryDashboardDAO.countGameSummaryMetrics(
|
||||
condition.periodType, condition.startTime, condition.endTime,
|
||||
PERIOD_ALL.equals(condition.periodType) ? PERIOD_ALL : null,
|
||||
condition.statTimezone, condition.countryKeyword, countryCodes, gameProvider, gameKeyword,
|
||||
condition.sysOrigin);
|
||||
condition.startPeriodKey, condition.endPeriodKey, condition.statTimezone,
|
||||
condition.countryKeyword, countryCodes, gameProvider, gameKeyword, condition.sysOrigin);
|
||||
List<CountryDashboardGameMetricCO> records = countryDashboardDAO.listGameSummaryMetrics(
|
||||
condition.periodType, condition.startTime, condition.endTime,
|
||||
PERIOD_ALL.equals(condition.periodType) ? PERIOD_ALL : null,
|
||||
condition.statTimezone, condition.countryKeyword, countryCodes, gameProvider, gameKeyword,
|
||||
condition.sysOrigin, sortSpec.column(), sortSpec.direction(), offset, limit)
|
||||
condition.startPeriodKey, condition.endPeriodKey, condition.statTimezone,
|
||||
condition.countryKeyword, countryCodes, gameProvider, gameKeyword, condition.sysOrigin,
|
||||
sortSpec.column(), sortSpec.direction(), offset, limit)
|
||||
.stream()
|
||||
.map(this::toCO)
|
||||
.toList();
|
||||
@ -168,8 +170,9 @@ public class CountryDashboardGameMetricServiceImpl implements CountryDashboardGa
|
||||
return countryDashboardDAO.listGameCountryRankMetrics(
|
||||
condition.periodType, condition.startTime, condition.endTime,
|
||||
PERIOD_ALL.equals(condition.periodType) ? PERIOD_ALL : null,
|
||||
condition.statTimezone, condition.countryKeyword, countryCodes, gameProvider, null,
|
||||
gameId, condition.sysOrigin, limit)
|
||||
condition.startPeriodKey, condition.endPeriodKey, condition.statTimezone,
|
||||
condition.countryKeyword, countryCodes, gameProvider, null, gameId, condition.sysOrigin,
|
||||
limit)
|
||||
.stream()
|
||||
.map(this::toCO)
|
||||
.toList();
|
||||
@ -639,12 +642,15 @@ public class CountryDashboardGameMetricServiceImpl implements CountryDashboardGa
|
||||
private final LocalDate endDateValue;
|
||||
private final LocalDateTime startTime;
|
||||
private final LocalDateTime endTime;
|
||||
private final String startPeriodKey;
|
||||
private final String endPeriodKey;
|
||||
private final String countryKeyword;
|
||||
private final String sysOrigin;
|
||||
|
||||
private QueryCondition(String periodType, String statTimezone, ZoneId statZoneId,
|
||||
LocalDate startDateValue, LocalDate endDateValue, LocalDateTime startTime,
|
||||
LocalDateTime endTime, String countryKeyword, String sysOrigin) {
|
||||
LocalDateTime endTime, String startPeriodKey, String endPeriodKey,
|
||||
String countryKeyword, String sysOrigin) {
|
||||
this.periodType = periodType;
|
||||
this.statTimezone = statTimezone;
|
||||
this.statZoneId = statZoneId;
|
||||
@ -652,6 +658,8 @@ public class CountryDashboardGameMetricServiceImpl implements CountryDashboardGa
|
||||
this.endDateValue = endDateValue;
|
||||
this.startTime = startTime;
|
||||
this.endTime = endTime;
|
||||
this.startPeriodKey = startPeriodKey;
|
||||
this.endPeriodKey = endPeriodKey;
|
||||
this.countryKeyword = countryKeyword;
|
||||
this.sysOrigin = sysOrigin;
|
||||
}
|
||||
@ -693,6 +701,10 @@ public class CountryDashboardGameMetricServiceImpl implements CountryDashboardGa
|
||||
: LocalDateTime.ofInstant(startInstant, STORAGE_ZONE_ID);
|
||||
LocalDateTime storageEndTime = endInstant == null ? null
|
||||
: LocalDateTime.ofInstant(endInstant, STORAGE_ZONE_ID);
|
||||
String startPeriodKey = PERIOD_DAY.equals(periodType) && start != null
|
||||
? start.format(DATE_FORMATTER) : null;
|
||||
String endPeriodKey = PERIOD_DAY.equals(periodType) && end != null
|
||||
? end.format(DATE_FORMATTER) : null;
|
||||
return new QueryCondition(
|
||||
periodType,
|
||||
statZoneId.getId(),
|
||||
@ -701,6 +713,8 @@ public class CountryDashboardGameMetricServiceImpl implements CountryDashboardGa
|
||||
end,
|
||||
storageStartTime,
|
||||
storageEndTime,
|
||||
startPeriodKey,
|
||||
endPeriodKey,
|
||||
trimToNull(cmd == null ? null : cmd.getCountryKeyword()),
|
||||
trimToNull(cmd == null ? null : cmd.getSysOrigin())
|
||||
);
|
||||
|
||||
@ -342,6 +342,8 @@ public interface CountryDashboardDAO extends BaseDAO<IUserBaseInfo> {
|
||||
@Param("startTime") LocalDateTime startTime,
|
||||
@Param("endTime") LocalDateTime endTime,
|
||||
@Param("periodKey") String periodKey,
|
||||
@Param("startPeriodKey") String startPeriodKey,
|
||||
@Param("endPeriodKey") String endPeriodKey,
|
||||
@Param("statTimezone") String statTimezone,
|
||||
@Param("countryKeyword") String countryKeyword,
|
||||
@Param("countryCodes") String countryCodes,
|
||||
@ -354,6 +356,8 @@ public interface CountryDashboardDAO extends BaseDAO<IUserBaseInfo> {
|
||||
@Param("startTime") LocalDateTime startTime,
|
||||
@Param("endTime") LocalDateTime endTime,
|
||||
@Param("periodKey") String periodKey,
|
||||
@Param("startPeriodKey") String startPeriodKey,
|
||||
@Param("endPeriodKey") String endPeriodKey,
|
||||
@Param("statTimezone") String statTimezone,
|
||||
@Param("countryKeyword") String countryKeyword,
|
||||
@Param("countryCodes") String countryCodes,
|
||||
@ -370,6 +374,8 @@ public interface CountryDashboardDAO extends BaseDAO<IUserBaseInfo> {
|
||||
@Param("startTime") LocalDateTime startTime,
|
||||
@Param("endTime") LocalDateTime endTime,
|
||||
@Param("periodKey") String periodKey,
|
||||
@Param("startPeriodKey") String startPeriodKey,
|
||||
@Param("endPeriodKey") String endPeriodKey,
|
||||
@Param("statTimezone") String statTimezone,
|
||||
@Param("countryKeyword") String countryKeyword,
|
||||
@Param("countryCodes") String countryCodes,
|
||||
@ -382,6 +388,8 @@ public interface CountryDashboardDAO extends BaseDAO<IUserBaseInfo> {
|
||||
@Param("startTime") LocalDateTime startTime,
|
||||
@Param("endTime") LocalDateTime endTime,
|
||||
@Param("periodKey") String periodKey,
|
||||
@Param("startPeriodKey") String startPeriodKey,
|
||||
@Param("endPeriodKey") String endPeriodKey,
|
||||
@Param("statTimezone") String statTimezone,
|
||||
@Param("countryKeyword") String countryKeyword,
|
||||
@Param("countryCodes") String countryCodes,
|
||||
@ -398,6 +406,8 @@ public interface CountryDashboardDAO extends BaseDAO<IUserBaseInfo> {
|
||||
@Param("startTime") LocalDateTime startTime,
|
||||
@Param("endTime") LocalDateTime endTime,
|
||||
@Param("periodKey") String periodKey,
|
||||
@Param("startPeriodKey") String startPeriodKey,
|
||||
@Param("endPeriodKey") String endPeriodKey,
|
||||
@Param("statTimezone") String statTimezone,
|
||||
@Param("countryKeyword") String countryKeyword,
|
||||
@Param("countryCodes") String countryCodes,
|
||||
|
||||
@ -121,6 +121,41 @@
|
||||
KEY `idx_game_lookup` (`sys_origin`, `stat_timezone`, `game_provider`, `game_id`, `period_type`, `period_key`),
|
||||
KEY `idx_game_period_sort` (`sys_origin`, `stat_timezone`, `period_type`, `period_key`, `consume_amount`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='国家数据大屏游戏维度周期预聚合'
|
||||
;
|
||||
|
||||
SET @current_schema = DATABASE();
|
||||
|
||||
SET @index_columns = (
|
||||
SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX)
|
||||
FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @current_schema
|
||||
AND TABLE_NAME = 'country_dashboard_game_period_metric'
|
||||
AND INDEX_NAME = 'idx_game_period_game'
|
||||
);
|
||||
SET @ddl = IF(
|
||||
@index_columns IS NULL,
|
||||
'ALTER TABLE `country_dashboard_game_period_metric` ADD KEY `idx_game_period_game` (`sys_origin`, `stat_timezone`, `period_type`, `period_key`, `game_provider`, `game_id`, `country_code`)',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE stmt FROM @ddl;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @index_columns = (
|
||||
SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX)
|
||||
FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @current_schema
|
||||
AND TABLE_NAME = 'country_dashboard_game_period_metric'
|
||||
AND INDEX_NAME = 'idx_game_rank_period'
|
||||
);
|
||||
SET @ddl = IF(
|
||||
@index_columns IS NULL,
|
||||
'ALTER TABLE `country_dashboard_game_period_metric` ADD KEY `idx_game_rank_period` (`sys_origin`, `stat_timezone`, `game_provider`, `game_id`, `period_type`, `period_key`, `country_code`)',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE stmt FROM @ddl;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
</update>
|
||||
|
||||
<update id="createGamePeriodUserMetricTable">
|
||||
@ -754,6 +789,10 @@
|
||||
<when test="periodType == 'ALL'">
|
||||
AND t.period_key = 'ALL'
|
||||
</when>
|
||||
<when test="periodType == 'DAY' and startPeriodKey != null and startPeriodKey != '' and endPeriodKey != null and endPeriodKey != ''">
|
||||
AND t.period_key >= #{startPeriodKey}
|
||||
AND t.period_key <= #{endPeriodKey}
|
||||
</when>
|
||||
<otherwise>
|
||||
<if test="startTime != null">
|
||||
AND t.period_start_date >= DATE(#{startTime})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user