Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/alpha' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrezza committed Jun 11, 2024
2 parents 8cb38d6 + 716925e commit 71bf464
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 89 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ jobs:
- name: Upload code coverage
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
# Set to `true` once codecov token bug is fixed; https://github.com/parse-community/parse-server/issues/9129
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
check-postgres:
strategy:
Expand Down
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
############################################################
FROM node:lts-alpine AS build

RUN apk --no-cache add git
RUN apk --no-cache add \
build-base \
git \
python3

WORKDIR /tmp

# Copy package.json first to benefit from layer caching
Expand Down
7 changes: 7 additions & 0 deletions changelogs/CHANGELOG_alpha.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [7.1.0-alpha.9](https://github.com/parse-community/parse-server/compare/7.1.0-alpha.8...7.1.0-alpha.9) (2024-05-27)


### Bug Fixes

* Parse Server option `extendSessionOnUse` not working for session lengths < 24 hours ([#9113](https://github.com/parse-community/parse-server/issues/9113)) ([0a054e6](https://github.com/parse-community/parse-server/commit/0a054e6b541fd5ab470bf025665f5f7d2acedaa0))

# [7.1.0-alpha.8](https://github.com/parse-community/parse-server/compare/7.1.0-alpha.7...7.1.0-alpha.8) (2024-05-16)


Expand Down
129 changes: 51 additions & 78 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "parse-server",
"version": "7.1.0-alpha.8",
"version": "7.1.0-alpha.9",
"description": "An express module providing a Parse-compatible API server",
"main": "lib/index.js",
"repository": {
Expand Down Expand Up @@ -52,7 +52,7 @@
"parse": "5.0.0",
"path-to-regexp": "6.2.1",
"pg-monitor": "2.0.0",
"pg-promise": "11.5.5",
"pg-promise": "11.7.8",
"pluralize": "8.0.0",
"rate-limit-redis": "4.2.0",
"redis": "4.6.13",
Expand Down
21 changes: 21 additions & 0 deletions spec/Auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,24 @@ describe('Auth', () => {
});
});
});

describe('extendSessionOnUse', () => {
it(`shouldUpdateSessionExpiry()`, async () => {
const { shouldUpdateSessionExpiry } = require('../lib/Auth');
let update = new Date(Date.now() - 86410 * 1000);

const res = shouldUpdateSessionExpiry(
{ sessionLength: 86460 },
{ updatedAt: update }
);

update = new Date(Date.now() - 43210 * 1000);
const res2 = shouldUpdateSessionExpiry(
{ sessionLength: 86460 },
{ updatedAt: update }
);

expect(res).toBe(true);
expect(res2).toBe(false);
});
});
17 changes: 13 additions & 4 deletions src/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ function nobody(config) {
return new Auth({ config, isMaster: false });
}

/**
* Checks whether session should be updated based on last update time & session length.
*/
function shouldUpdateSessionExpiry(config, session) {
const resetAfter = config.sessionLength / 2;
const lastUpdated = new Date(session?.updatedAt);
const skipRange = new Date();
skipRange.setTime(skipRange.getTime() - resetAfter * 1000);
return lastUpdated <= skipRange;
}

const throttle = {};
const renewSessionIfNeeded = async ({ config, session, sessionToken }) => {
if (!config?.extendSessionOnUse) {
Expand All @@ -88,10 +99,7 @@ const renewSessionIfNeeded = async ({ config, session, sessionToken }) => {
const { results } = await query.execute();
session = results[0];
}
const lastUpdated = new Date(session?.updatedAt);
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
if (lastUpdated > yesterday || !session) {
if (!shouldUpdateSessionExpiry(config, session) || !session) {
return;
}
const expiresAt = config.generateSessionExpiresAt();
Expand Down Expand Up @@ -579,6 +587,7 @@ module.exports = {
maintenance,
nobody,
readOnly,
shouldUpdateSessionExpiry,
getAuthForSessionToken,
getAuthForLegacySessionToken,
findUsersWithAuthData,
Expand Down
3 changes: 2 additions & 1 deletion src/Options/Definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ module.exports.ParseServerOptions = {
},
extendSessionOnUse: {
env: 'PARSE_SERVER_EXTEND_SESSION_ON_USE',
help: 'Whether Parse Server should automatically extend a valid session by the sessionLength',
help:
"Whether Parse Server should automatically extend a valid session by the sessionLength. In order to reduce the number of session updates in the database, a session will only be extended when a request is received after at least half of the current session's lifetime has passed.",
action: parsers.booleanParser,
default: false,
},
Expand Down
2 changes: 1 addition & 1 deletion src/Options/docs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export interface ParseServerOptions {
/* Session duration, in seconds, defaults to 1 year
:DEFAULT: 31536000 */
sessionLength: ?number;
/* Whether Parse Server should automatically extend a valid session by the sessionLength
/* Whether Parse Server should automatically extend a valid session by the sessionLength. In order to reduce the number of session updates in the database, a session will only be extended when a request is received after at least half of the current session's lifetime has passed.
:DEFAULT: false */
extendSessionOnUse: ?boolean;
/* Default value for limit option on queries, defaults to `100`.
Expand Down

0 comments on commit 71bf464

Please sign in to comment.