@golemio/ndic 1.4.1-dev.1685774441 → 1.4.1-dev.1685779508

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.
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ var dbm;
4
+ var type;
5
+ var seed;
6
+ var fs = require('fs');
7
+ var path = require('path');
8
+ var Promise;
9
+
10
+ /**
11
+ * We receive the dbmigrate dependency from dbmigrate initially.
12
+ * This enables us to not have to rely on NODE_PATH.
13
+ */
14
+ exports.setup = function(options, seedLink) {
15
+ dbm = options.dbmigrate;
16
+ type = dbm.dataType;
17
+ seed = seedLink;
18
+ Promise = options.Promise;
19
+ };
20
+
21
+ exports.up = function(db) {
22
+ var filePath = path.join(__dirname, 'sqls', '20250220160454-optimize-traffic-restrictions-up.sql');
23
+ return new Promise( function( resolve, reject ) {
24
+ fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
25
+ if (err) return reject(err);
26
+ console.log('received data: ' + data);
27
+
28
+ resolve(data);
29
+ });
30
+ })
31
+ .then(function(data) {
32
+ return db.runSql(data);
33
+ });
34
+ };
35
+
36
+ exports.down = function(db) {
37
+ var filePath = path.join(__dirname, 'sqls', '20250220160454-optimize-traffic-restrictions-down.sql');
38
+ return new Promise( function( resolve, reject ) {
39
+ fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
40
+ if (err) return reject(err);
41
+ console.log('received data: ' + data);
42
+
43
+ resolve(data);
44
+ });
45
+ })
46
+ .then(function(data) {
47
+ return db.runSql(data);
48
+ });
49
+ };
50
+
51
+ exports._meta = {
52
+ "version": 1
53
+ };
@@ -0,0 +1,5 @@
1
+ drop function fetch_valid_traffic_restrictions(timestamptz);
2
+ drop index ndic_traffic_restrictions_regions_situation_record_id_idx;
3
+ drop index ndic_traffic_restrictions_situation_record_id_idx;
4
+ drop index ndic_traffic_restrictions_regions_validity_overall_time_idx;
5
+ drop index ndic_traffic_restrictions_validity_overall_time_idx;
@@ -0,0 +1,48 @@
1
+ create or replace function fetch_valid_traffic_restrictions(validity_datetime timestamptz)
2
+ returns setof v_traffic_restrictions_all
3
+ language sql
4
+ set search_path from current
5
+ as $function$
6
+ select *
7
+ from (
8
+ select distinct on (situation_record_id) *
9
+ from v_traffic_restrictions_all
10
+ where situation_record_id in (
11
+ select distinct situation_record_id
12
+ from v_traffic_restrictions_all
13
+ where
14
+ validity_overall_start_time < validity_datetime
15
+ and validity_overall_end_time > validity_datetime
16
+ )
17
+ order by situation_record_id, situation_record_version_time desc
18
+ ) tmp
19
+ where
20
+ tmp.validity_overall_start_time < validity_datetime
21
+ and tmp.validity_overall_end_time > validity_datetime
22
+ ;
23
+ $function$
24
+ ;
25
+
26
+ comment on function fetch_valid_traffic_restrictions(timestamptz) is E''
27
+ 'Get all traffic restrictions (both from Prague and from regions) with'
28
+ ' validity_overall_start_time < validity_datetime < validity_overall_end_time. Only one row per situation_record_id will be'
29
+ ' returned - the one with the highest situation_record_version_time.'
30
+ ;
31
+
32
+ create index ndic_traffic_restrictions_regions_situation_record_id_idx
33
+ on ndic_traffic_restrictions_regions
34
+ using hash (situation_record_id)
35
+ ;
36
+ create index ndic_traffic_restrictions_situation_record_id_idx
37
+ on ndic_traffic_restrictions
38
+ using hash (situation_record_id)
39
+ ;
40
+
41
+ create index ndic_traffic_restrictions_regions_validity_overall_time_idx
42
+ on ndic_traffic_restrictions_regions
43
+ using btree (validity_overall_start_time, validity_overall_end_time)
44
+ ;
45
+ create index ndic_traffic_restrictions_validity_overall_time_idx
46
+ on ndic_traffic_restrictions
47
+ using btree (validity_overall_start_time, validity_overall_end_time)
48
+ ;
@@ -33,27 +33,12 @@ class TrafficRestrictionsModel extends models_1.SequelizeModel {
33
33
  try {
34
34
  // take moment from request or now
35
35
  let queryMoment = reqMoment ? reqMoment : (0, helpers_1.dateTime)(new Date()).setTimeZone("Europe/Prague").toISOString();
36
- // get rows for each `situation_record_id`,
37
- // but with MAX `situation_record_version_time` for each `situation_record_id`
38
36
  let query = `
39
37
  SELECT *
40
- FROM
41
- (
42
- SELECT
43
- row_number() OVER (partition by situation_record_id
44
- ORDER BY
45
- situation_record_version_time desc) rn,
46
- *
47
- FROM
48
- ${index_1.Ndic.pgSchema}.v_traffic_restrictions_all
49
- )
50
- a
51
- WHERE rn = 1
52
- AND validity_overall_start_time < '${queryMoment}'
53
- AND validity_overall_end_time > '${queryMoment}'
38
+ FROM ${index_1.Ndic.pgSchema}.fetch_valid_traffic_restrictions(:queryMoment)
54
39
  `;
55
40
  if (situationRecordType) {
56
- query += ` AND situation_record_type = '${situationRecordType}'`;
41
+ query += "WHERE situation_record_type = :situationRecordType";
57
42
  }
58
43
  if (limit) {
59
44
  query += ` LIMIT ${limit}`;
@@ -61,7 +46,9 @@ class TrafficRestrictionsModel extends models_1.SequelizeModel {
61
46
  if (offset) {
62
47
  query += ` OFFSET ${offset}`;
63
48
  }
64
- const trafficRestrictionsFromDB = (yield (database_1.sequelizeConnection === null || database_1.sequelizeConnection === void 0 ? void 0 : database_1.sequelizeConnection.query(query)));
49
+ const trafficRestrictionsFromDB = (yield (database_1.sequelizeConnection === null || database_1.sequelizeConnection === void 0 ? void 0 : database_1.sequelizeConnection.query(query, {
50
+ replacements: { queryMoment, situationRecordType },
51
+ })));
65
52
  return trafficRestrictionsFromDB[0] || [];
66
53
  }
67
54
  catch (err) {
@@ -1 +1 @@
1
- {"version":3,"file":"TrafficRestrictionsModel.js","sourceRoot":"","sources":["../../../src/output-gateway/models/TrafficRestrictionsModel.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,0DAAkC;AAClC,yEAAiF;AACjF,qEAA0E;AAC1E,6EAAwE;AACxE,wDAAsD;AAEtD,MAAa,wBAAyB,SAAQ,uBAAc;IACxD;QACI,KAAK,CAAC,YAAI,CAAC,oBAAoB,CAAC,IAAI,EAAE,4BAA4B,EAAE,YAAI,CAAC,oBAAoB,CAAC,yBAAyB,EAAE;YACrH,MAAM,EAAE,YAAI,CAAC,QAAQ;S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DA0EC"}
1
+ {"version":3,"file":"TrafficRestrictionsModel.js","sourceRoot":"","sources":["../../../src/output-gateway/models/TrafficRestrictionsModel.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,0DAAkC;AAClC,yEAAiF;AACjF,qEAA0E;AAC1E,6EAAwE;AACxE,wDAAsD;AAEtD,MAAa,wBAAyB,SAAQ,uBAAc;IACxD;QACI,KAAK,CAAC,YAAI,CAAC,oBAAoB,CAAC,IAAI,EAAE,4BAA4B,EAAE,YAAI,CAAC,oBAAoB,CAAC,yBAAyB,EAAE;YACrH,MAAM,EAAE,YAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QAGP;;;;;;;WAOG;QAEI,WAAM,GAAG,CACZ,UAKI,EAAE,EAC8B,EAAE;YACtC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC;YAElE,IAAI;gBACA,kCAAkC;gBAClC,IAAI,WAAW,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAA,kBAAQ,EAAC,IAAI,IAAI,EAAE,CAAC,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC,WAAW,EAAE,CAAC;gBAE1G,IAAI,KAAK,GAAG;;mBAEL,YAAI,CAAC,QAAQ;aACnB,CAAC;gBAEF,IAAI,mBAAmB,EAAE;oBACrB,KAAK,IAAI,oDAAoD,CAAC;iBACjE;gBAED,IAAI,KAAK,EAAE;oBACP,KAAK,IAAI,UAAU,KAAK,EAAE,CAAC;iBAC9B;gBAED,IAAI,MAAM,EAAE;oBACR,KAAK,IAAI,WAAW,MAAM,EAAE,CAAC;iBAChC;gBAED,MAAM,yBAAyB,GAAG,CAAC,MAAM,CAAA,8BAAmB,aAAnB,8BAAmB,uBAAnB,8BAAmB,CAAE,KAAK,CAAC,KAAK,EAAE;oBACvE,YAAY,EAAE,EAAE,WAAW,EAAE,mBAAmB,EAAE;iBACrD,CAAC,CAAA,CAAkC,CAAC;gBAErC,OAAO,yBAAyB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aAC7C;YAAC,OAAO,GAAG,EAAE;gBACV,MAAM,IAAI,6BAAY,CAAC,gBAAgB,EAAE,0BAA0B,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;aAClF;QACL,CAAC,CAAA,CAAC;QAEK,WAAM,GAAG,CAAO,EAAU,EAA0B,EAAE;YACzD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACvC,CAAC,CAAA,CAAC;IAtDF,CAAC;CAuDJ;AA5DD,4DA4DC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@golemio/ndic",
3
- "version": "1.4.1-dev.1685774441",
3
+ "version": "1.4.1-dev.1685779508",
4
4
  "description": "Golemio NDIC Module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",