@socialgouv/matomo-postgres 2.3.13 → 2.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/run.test.js +0 -4
- package/dist/importEvent.js +66 -47
- package/package.json +1 -1
|
@@ -84,10 +84,6 @@ test('run: should run SQL queries', () => __awaiter(void 0, void 0, void 0, func
|
|
|
84
84
|
jest.useFakeTimers().setSystemTime(TEST_DATE.getTime());
|
|
85
85
|
const result = yield run();
|
|
86
86
|
expect(queries).toMatchSnapshot();
|
|
87
|
-
// Updated expectation based on actual behavior with INITIAL_OFFSET=3 (5 days total: 3 days before + today + 1 day after)
|
|
88
|
-
// 5 days * (6 events per day + 1 count query per day)
|
|
89
|
-
// Note: We also capture the initial "findLastEventInMatomo" query.
|
|
90
|
-
expect(queries.length).toEqual(1 + 5 * (6 + 1));
|
|
91
87
|
expect(result).toMatchObject({
|
|
92
88
|
daysProcessed: 5,
|
|
93
89
|
eventsImportedTotal: 5 * 6
|
package/dist/importEvent.js
CHANGED
|
@@ -8,7 +8,53 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { sql } from 'kysely';
|
|
11
|
+
import { DESTINATION_TABLE, PARTITIONED_MATOMO_TABLE_NAME } from './config.js';
|
|
11
12
|
import { db, pool } from './db.js';
|
|
13
|
+
const MATOMO_INSERT_COLUMNS = [
|
|
14
|
+
'action_id',
|
|
15
|
+
'action_timestamp',
|
|
16
|
+
'idsite',
|
|
17
|
+
'idvisit',
|
|
18
|
+
'actions',
|
|
19
|
+
'country',
|
|
20
|
+
'region',
|
|
21
|
+
'city',
|
|
22
|
+
'operatingsystemname',
|
|
23
|
+
'devicemodel',
|
|
24
|
+
'devicebrand',
|
|
25
|
+
'visitduration',
|
|
26
|
+
'dayssincefirstvisit',
|
|
27
|
+
'visitortype',
|
|
28
|
+
'sitename',
|
|
29
|
+
'userid',
|
|
30
|
+
'serverdateprettyfirstaction',
|
|
31
|
+
'action_type',
|
|
32
|
+
'action_eventcategory',
|
|
33
|
+
'action_eventaction',
|
|
34
|
+
'action_eventname',
|
|
35
|
+
'action_eventvalue',
|
|
36
|
+
'action_timespent',
|
|
37
|
+
'usercustomproperties',
|
|
38
|
+
'usercustomdimensions',
|
|
39
|
+
'dimension1',
|
|
40
|
+
'dimension2',
|
|
41
|
+
'dimension3',
|
|
42
|
+
'dimension4',
|
|
43
|
+
'dimension5',
|
|
44
|
+
'dimension6',
|
|
45
|
+
'dimension7',
|
|
46
|
+
'dimension8',
|
|
47
|
+
'dimension9',
|
|
48
|
+
'dimension10',
|
|
49
|
+
'action_url',
|
|
50
|
+
'sitesearchkeyword',
|
|
51
|
+
'action_title',
|
|
52
|
+
'visitorid',
|
|
53
|
+
'referrertype',
|
|
54
|
+
'referrername',
|
|
55
|
+
'resolution'
|
|
56
|
+
];
|
|
57
|
+
const MATOMO_INSERT_COLUMN_SQL = sql.join(MATOMO_INSERT_COLUMNS.map((column) => sql.id(column)), sql `,\n`);
|
|
12
58
|
/**
|
|
13
59
|
*
|
|
14
60
|
* @param {Client} client
|
|
@@ -81,53 +127,26 @@ export const importEvent = (event) => __awaiter(void 0, void 0, void 0, function
|
|
|
81
127
|
if (!pool || typeof pool.connect !== 'function') {
|
|
82
128
|
throw new Error('Database connection pool is invalid or undefined');
|
|
83
129
|
}
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
${
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
${eventData.action_type},
|
|
105
|
-
${eventData.action_eventcategory},
|
|
106
|
-
${eventData.action_eventaction},
|
|
107
|
-
${eventData.action_eventname},
|
|
108
|
-
${eventData.action_eventvalue},
|
|
109
|
-
${eventData.action_timespent},
|
|
110
|
-
${eventData.usercustomproperties},
|
|
111
|
-
${eventData.usercustomdimensions},
|
|
112
|
-
${eventData.dimension1},
|
|
113
|
-
${eventData.dimension2},
|
|
114
|
-
${eventData.dimension3},
|
|
115
|
-
${eventData.dimension4},
|
|
116
|
-
${eventData.dimension5},
|
|
117
|
-
${eventData.dimension6},
|
|
118
|
-
${eventData.dimension7},
|
|
119
|
-
${eventData.dimension8},
|
|
120
|
-
${eventData.dimension9},
|
|
121
|
-
${eventData.dimension10},
|
|
122
|
-
${eventData.action_url},
|
|
123
|
-
${eventData.sitesearchkeyword},
|
|
124
|
-
${eventData.action_title},
|
|
125
|
-
${eventData.visitorid},
|
|
126
|
-
${eventData.referrertype},
|
|
127
|
-
${eventData.referrername},
|
|
128
|
-
${eventData.resolution}
|
|
129
|
-
)
|
|
130
|
-
`.execute(db);
|
|
130
|
+
// Use different insertion logic based on DESTINATION_TABLE
|
|
131
|
+
if (DESTINATION_TABLE === PARTITIONED_MATOMO_TABLE_NAME) {
|
|
132
|
+
// Use stored procedure for partitioned table (handles automatic partition creation)
|
|
133
|
+
yield sql `
|
|
134
|
+
SELECT insert_into_matomo_partitioned(
|
|
135
|
+
${sql.join(MATOMO_INSERT_COLUMNS.map((column) => sql `${eventData[column]}`), sql `, `)}
|
|
136
|
+
)
|
|
137
|
+
`.execute(db);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
// Direct INSERT for standard (non-partitioned) table
|
|
141
|
+
yield sql `
|
|
142
|
+
INSERT INTO ${sql.id(DESTINATION_TABLE)} (
|
|
143
|
+
${MATOMO_INSERT_COLUMN_SQL}
|
|
144
|
+
) VALUES (
|
|
145
|
+
${sql.join(MATOMO_INSERT_COLUMNS.map((column) => sql `${eventData[column]}`), sql `, `)}
|
|
146
|
+
)
|
|
147
|
+
ON CONFLICT (action_id) DO NOTHING
|
|
148
|
+
`.execute(db);
|
|
149
|
+
}
|
|
131
150
|
}
|
|
132
151
|
catch (err) {
|
|
133
152
|
// Add context for troubleshooting
|
package/package.json
CHANGED