diff --git a/Dockerfile b/Dockerfile index 45b9d380..7d16c37b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,8 @@ FROM node:10-alpine +# pg-native +RUN apk --no-cache add make python gcc postgresql-dev g++ + # enable node_modules caching layer RUN apk add --no-cache tini git ADD package.json /tmp/package.json @@ -18,5 +21,4 @@ ENTRYPOINT ["/sbin/tini", "--"] # NodeJS launch USER node -ENV NODE_ENV production -CMD ["node", "--max-old-space-size=2048", "dist/index.js"] \ No newline at end of file +CMD ["npm", "start"] \ No newline at end of file diff --git a/nodemon.json b/nodemon.json deleted file mode 100644 index e1a3c26a..00000000 --- a/nodemon.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "watch": ["dist/**/*.js"] -} diff --git a/package-lock.json b/package-lock.json index 36df7a27..8c12cca2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "data-service", - "version": "0.35.0", + "version": "0.36.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1324,6 +1324,14 @@ "integrity": "sha512-Un7MIEDdUC5gNpcGDV97op1Ywk748MpHcFTHoYs6qnj1Z3j7I53VG3nwZhKzoBZmbdRNnb6WRdFlwl7tSDuZGw==", "dev": true }, + "bindings": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "requires": { + "file-uri-to-path": "1.0.0" + } + }, "bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", @@ -1810,8 +1818,7 @@ "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", - "dev": true + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, "cowsay": { "version": "1.3.0", @@ -2699,6 +2706,11 @@ "flat-cache": "^2.0.1" } }, + "file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" + }, "fileset": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/fileset/-/fileset-2.0.3.tgz", @@ -5176,6 +5188,15 @@ "type-check": "~0.3.2" } }, + "libpq": { + "version": "1.8.12", + "resolved": "https://registry.npmjs.org/libpq/-/libpq-1.8.12.tgz", + "integrity": "sha512-4lUY9BD9suz76mVS0kH4rRgRy620g/c9YZH5GYC3smfIpjtj6KiPuQ4IwQSHSZMMMhMM3tBFrYUrw8mHOOZVeg==", + "requires": { + "bindings": "1.5.0", + "nan": "^2.14.0" + } + }, "liftoff": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/liftoff/-/liftoff-3.1.0.tgz", @@ -5507,9 +5528,7 @@ "nan": { "version": "2.14.0", "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", - "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==", - "dev": true, - "optional": true + "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==" }, "nanomatch": { "version": "1.2.13", @@ -6155,6 +6174,39 @@ "cli-color": "1.4.0" } }, + "pg-native": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/pg-native/-/pg-native-3.0.1.tgz", + "integrity": "sha512-LBVNWkNh0fVx/cienARRP2y22J5OpUsKBe0TpxzAx3arEUUdIs77aLSAHS3scS7SMaqc+OkG40CEu5fN0/cjIw==", + "requires": { + "libpq": "^1.8.10", + "pg-types": "^1.12.1", + "readable-stream": "1.0.31" + }, + "dependencies": { + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==" + }, + "readable-stream": { + "version": "1.0.31", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.31.tgz", + "integrity": "sha512-tco/Dwv1f/sgIgN6CWdj/restacPKNskK6yps1981ivH2ZmLYcs5o5rVzL3qaO/cSkhN8hYOMWs7+glzOLSgRg==", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "0.0.1", + "string_decoder": "~0.10.x" + } + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==" + } + } + }, "pg-pool": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-2.0.5.tgz", diff --git a/package.json b/package.json index 8a04f7bf..1abbcef6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "data-service", - "version": "0.35.0", + "version": "0.36.0", "description": "Waves data service", "main": "src/index.js", "repository": "git@github.com:wavesplatform/data-service.git", @@ -8,20 +8,13 @@ "license": "MIT", "scripts": { "build": "rm -rf dist/ && tsc", - "start": "export $(cat variables.env | xargs) && NODE_ENV=production node dist/index.js", - "candles": "export $(cat variables.env | xargs) && NODE_ENV=production node dist/daemons/candles/index.js", - "dev:candles": "export $(cat variables.stage.env | xargs) && NODE_ENV=development LOG_LEVEL=debug nodemon --inspect dist/daemons/candles/index.js", - "dev:candles:t": "export $(cat variables.testnet.env | xargs) && NODE_ENV=development LOG_LEVEL=debug nodemon --inspect dist/daemons/candles/index.js", - "pairs": "export $(cat variables.env | xargs) && NODE_ENV=production node dist/daemons/pairs/index.js", - "dev:pairs": "export $(cat variables.stage.env | xargs) && NODE_ENV=development LOG_LEVEL=debug nodemon --inspect dist/daemons/pairs/index.js", - "dev:pairs:t": "export $(cat variables.testnet.env | xargs) && NODE_ENV=development LOG_LEVEL=debug nodemon --inspect dist/daemons/pairs/index.js", + "start": "NODE_PG_FORCE_NATIVE=1 node dist/index.js", + "dev": "NODE_PG_FORCE_NATIVE=1 NODE_ENV=development LOG_LEVEL=debug node dist/index.js", + "candles": "NODE_PG_FORCE_NATIVE=1 node dist/daemons/candles/index.js", + "pairs": "NODE_PG_FORCE_NATIVE=1 node dist/daemons/pairs/index.js", "lint": "eslint src", - "dev": "NODE_ENV=development LOG_LEVEL=debug nodemon --inspect dist/index.js", - "test": "npm run test:u && npm run test:i", - "test:t": "npm run test:u && npm run test:it", - "test:u": "jest --runInBand --detectOpenHandles --config=config/jest.config.unit.json", + "test": "jest --runInBand --detectOpenHandles --config=config/jest.config.unit.json", "test:i": "export $(cat variables.env | xargs) && jest --runInBand --detectOpenHandles --config=config/jest.config.integration.json", - "test:is": "export $(cat variables.stage.env | xargs) && jest --runInBand --detectOpenHandles --config=config/jest.config.integration.json", "test:it": "export $(cat variables.testnet.env | xargs) && jest --runInBand --detectOpenHandles --config=config/jest.config.integration.testnet.json" }, "devDependencies": { @@ -37,7 +30,6 @@ "@types/ramda": "^0.25.43", "eslint": "^5.15.1", "jest": "^24.5.0", - "nodemon": "^1.18.8", "pg-monitor": "^1.3.1", "ts-jest": "^23.10.5", "ts-node": "^7.0.1", @@ -61,6 +53,7 @@ "koa-router": "^7.4.0", "lru-cache": "^5.1.1", "merge-descriptors": "^1.0.1", + "pg-native": "^3.0.1", "pg-promise": "^8.2.3", "qs": "^6.5.2", "ramda": "^0.25.0", diff --git a/src/daemons/candles/Dockerfile b/src/daemons/candles/Dockerfile index f442eebd..fba0d583 100644 --- a/src/daemons/candles/Dockerfile +++ b/src/daemons/candles/Dockerfile @@ -1,5 +1,8 @@ FROM node:10-alpine +# pg-native +RUN apk --no-cache add make python gcc postgresql-dev g++ + # enable node_modules caching layer RUN apk add --no-cache tini git ADD package.json /tmp/package.json @@ -18,5 +21,4 @@ ENTRYPOINT ["/sbin/tini", "--"] # NodeJS launch USER node -ENV NODE_ENV production -CMD ["node", "--max-old-space-size=2048", "dist/daemons/candles/index.js"] +CMD ["npm", "run", "candles"] diff --git a/src/daemons/pairs/Dockerfile b/src/daemons/pairs/Dockerfile index 31296a96..74bcd5ca 100644 --- a/src/daemons/pairs/Dockerfile +++ b/src/daemons/pairs/Dockerfile @@ -1,5 +1,8 @@ FROM node:10-alpine +# pg-native +RUN apk --no-cache add make python gcc postgresql-dev g++ + # enable node_modules caching layer RUN apk add --no-cache tini git ADD package.json /tmp/package.json @@ -18,5 +21,4 @@ ENTRYPOINT ["/sbin/tini", "--"] # NodeJS launch USER node -ENV NODE_ENV production -CMD ["node", "--max-old-space-size=2048", "dist/daemons/pairs/index.js"] +CMD ["npm", "run", "pairs"] diff --git a/src/http/_common/filters/filters.ts b/src/http/_common/filters/filters.ts index 9766baaf..566473ab 100644 --- a/src/http/_common/filters/filters.ts +++ b/src/http/_common/filters/filters.ts @@ -12,7 +12,7 @@ import { DEFAULT_MAX_LIMIT } from './'; import { CommonFilters } from './types'; // default limit is 100 -const limitFilter = +export const limit = (max: number): CommonFilters['limit'] => (raw) => { if (isNil(raw)) { @@ -30,25 +30,25 @@ const limitFilter = }; // default sort is SortOrder.Descending -const sortFilter: CommonFilters['sort'] = (s) => +const sort: CommonFilters['sort'] = (s) => typeof s === 'undefined' ? ok(undefined) : isSortOrder(s) ? ok(s) : error(new ParseError(new Error('Invalid sort value'))); -const afterFilter: CommonFilters['after'] = parseTrimmedStringIfDefined; +const after: CommonFilters['after'] = parseTrimmedStringIfDefined; export default { timeStart: parseDate, timeEnd: parseDate, blockTimeStart: parseDate, blockTimeEnd: parseDate, - limit: limitFilter(DEFAULT_MAX_LIMIT), + limit: limit(DEFAULT_MAX_LIMIT), sender: parseTrimmedStringIfDefined, senders: parseArrayQuery, - sort: sortFilter, - after: afterFilter, + sort, + after, ids: parseArrayQuery, query: parseTrimmedStringIfDefined, }; diff --git a/src/http/pairs/utils.ts b/src/http/pairs/utils.ts index a7b85dd3..647b9106 100644 --- a/src/http/pairs/utils.ts +++ b/src/http/pairs/utils.ts @@ -11,9 +11,11 @@ import { parseArrayQuery, parseBool, parsePairs } from '../../utils/parsers'; import { ParseArrayQuery } from '../../utils/parsers/parseArrayQuery'; import { parseFilterValues } from '../_common/filters'; import { ParsedFilterValues, Parser } from '../_common/filters/types'; -import commonFilters from '../_common/filters/filters'; +import commonFilters, { limit } from '../_common/filters/filters'; import { withMatcher } from '../_common/utils'; +const PAIRS_MAX_LIMIT = 1000; + export type ParseMatchExactly = Parser; export const parseMatchExactly: ParseMatchExactly = ( matchExactlyRaw?: string @@ -40,6 +42,7 @@ export const mgetOrSearchParser = parseFilterValues({ match_exactly: parseMatchExactly, search_by_asset: commonFilters.query, search_by_assets: parseArrayQuery as ParseArrayQuery, // merge function type and overloads + limit: limit(PAIRS_MAX_LIMIT), }); type ParserFnType = typeof mgetOrSearchParser;