Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement session.all() #343

Merged
merged 1 commit into from
Oct 18, 2018
Merged

implement session.all() #343

merged 1 commit into from
Oct 18, 2018

Conversation

wtflink
Copy link
Member

@wtflink wtflink commented Oct 1, 2018

close #316

@codecov-io
Copy link

codecov-io commented Oct 1, 2018

Codecov Report

Merging #343 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #343      +/-   ##
==========================================
+ Coverage   90.34%   90.37%   +0.02%     
==========================================
  Files         112      112              
  Lines        3324     3334      +10     
  Branches      791      791              
==========================================
+ Hits         3003     3013      +10     
  Misses        281      281              
  Partials       40       40
Impacted Files Coverage Δ
src/session/MongoSessionStore.js 100% <100%> (ø) ⬆️
src/cache/RedisCacheStore.js 100% <100%> (ø) ⬆️
src/cache/MemoryCacheStore.js 100% <100%> (ø) ⬆️
src/session/CacheBasedSessionStore.js 100% <100%> (ø) ⬆️
src/session/FileSessionStore.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0517b9b...6053ec3. Read the comment docs.

@@ -5,6 +5,7 @@ import { type Session } from './Session';
export interface SessionStore {
init(): Promise<SessionStore>;
read(key: string): Promise<Session | null>;
all(): Promise<Array<?Session>>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Promise<Array<Session>>

@@ -27,6 +27,10 @@ export default class CacheBasedSessionStore implements SessionStore {
return (this._cache.get(key): any);
}

async all(): Promise<Array<?Session>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Promise<Array<Session>>

@@ -8,6 +7,7 @@ import { type Session } from './Session';
import { type SessionStore } from './SessionStore';

type MongoCollection = {
find: () => { toArray: () => Promise<Array<any>> },
Copy link
Collaborator

@chentsulin chentsulin Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find returns a Cursor: http://mongodb.github.io/node-mongodb-native/2.2/api/Cursor.html

type Cursor = {
  toArray: () => Promise<Array<any>>
};

type MongoCollection = {
  find: () => Cursor
  // 
};

@@ -61,6 +61,17 @@ export default class MongoSessionStore implements SessionStore {
}
}

async all(): Promise<Array<?Session>> {
try {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not try catch here for the user, just return it:

return this._sessions.find().toArray();

@wtflink wtflink force-pushed the implement-session.all() branch 2 times, most recently from f909a50 to 6c2d9e8 Compare October 11, 2018 07:12
await store.put('x', { a: 1 }, 5);
await store.put('y', { a: 2 }, 5);

const result1 = await store.all();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why using result1 instead of result?


const result1 = await store.all();

expect(result1).toEqual(expect.arrayContaining([{ a: 1 }, { a: 2 }]));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work without arrayContaining

@@ -39,6 +39,11 @@ export default class FileSessionStore implements SessionStore {
return session;
}

async all(): Promise<Array<Session>> {
const sessions = await this._jfs.all();
return sessions;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return this._jfs.all()

@wtflink wtflink force-pushed the implement-session.all() branch 2 times, most recently from cd14741 to fc50702 Compare October 12, 2018 02:31

while (cursor !== '0') {
/* eslint-disable no-await-in-loop */
const result = await this._redis.scan(cursor);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const [nextCursor, newkeys] = await this._redis.scan(cursor);
cursor = nextCursor;
keys = keys.concat(newkeys);

@chentsulin chentsulin merged commit 0b749f8 into master Oct 18, 2018
@chentsulin chentsulin deleted the implement-session.all() branch October 18, 2018 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Loop through sessions
3 participants