-
-
Notifications
You must be signed in to change notification settings - Fork 574
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Accidental improvements whilst helping Jem on the docs... (#2067)
- Loading branch information
Showing
24 changed files
with
506 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"grafast": patch | ||
--- | ||
|
||
Add `nodeIdFromNode()` helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"grafast": patch | ||
--- | ||
|
||
Fix performance issue in `loadOne()`/`loadMany()` due to using | ||
`setTimeout(cb, 0)`, now using `process.nextTick(cb)`. High enough concurrency | ||
and the issue goes away, but with limited concurrency this causes a lot of | ||
`(idle)` in profiling and thus completing 10k items took longer. (Lots of time | ||
spent in `epoll_pwait`.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"grafast": patch | ||
--- | ||
|
||
Allow applying `if` to `inhibitOnNull` - e.g. only inhibit on null if some other | ||
condition matches. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 0 additions & 48 deletions
48
grafast/website/examples/users-and-friends/businessLogic.js
This file was deleted.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
grafast/website/examples/users-and-friends/businessLogic.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Business logic is the same for Grafast and GraphQL | ||
*/ | ||
|
||
import { db } from "./database.mjs"; | ||
|
||
const logSql = process.env.LOG_SQL === "1"; | ||
|
||
const queryAll = (query, parameters) => | ||
new Promise((resolve, reject) => { | ||
if (logSql) { | ||
console.log({ query, parameters }); | ||
} | ||
return db.all(query, parameters, (err, result) => | ||
err ? reject(err) : resolve(result), | ||
); | ||
}); | ||
|
||
export async function getUsersByIds(ids, options = {}) { | ||
const columns = options.columns | ||
? [...new Set(["id", ...options.columns])] | ||
: ["*"]; | ||
const users = await queryAll( | ||
`select ${columns.join(", ")} from users where id in (${ids | ||
.map(() => `?`) | ||
.join(", ")})`, | ||
ids, | ||
); | ||
return ids.map((id) => users.find((u) => u.id === id)); | ||
} | ||
|
||
export async function getPostsByIds(ids, options = {}) { | ||
const columns = options.columns | ||
? [...new Set(["id", ...options.columns])] | ||
: ["*"]; | ||
const posts = await queryAll( | ||
`select ${columns.join(", ")} from posts where id in (${ids | ||
.map(() => `?`) | ||
.join(", ")})`, | ||
ids, | ||
); | ||
return ids.map((id) => posts.find((u) => u.id === id)); | ||
} | ||
|
||
export async function getFriendshipsByUserIds(userIds, options = {}) { | ||
const columns = options.columns | ||
? [...new Set(["user_id", ...options.columns])] | ||
: ["*"]; | ||
const friendships = await queryAll( | ||
`select ${columns.join(", ")} from friendships where user_id in (${userIds | ||
.map(() => `?`) | ||
.join(", ")})`, | ||
userIds, | ||
); | ||
return userIds.map((userId) => | ||
friendships.filter((f) => f.user_id === userId), | ||
); | ||
} | ||
|
||
export async function getPostsByAuthorIds(rawUserIds, options = {}) { | ||
const userIds = rawUserIds.filter((uid) => uid != null && uid >= 0); | ||
const columns = options.columns | ||
? [...new Set(["author_id", ...options.columns])] | ||
: ["*"]; | ||
const posts = | ||
userIds.length > 0 | ||
? await queryAll( | ||
`select ${columns.join(", ")} from posts where author_id in (${userIds | ||
.map(() => `?`) | ||
.join(", ")})`, | ||
userIds, | ||
) | ||
: []; | ||
const anonymousPosts = | ||
userIds.length !== rawUserIds.length | ||
? await queryAll( | ||
`select ${columns.join(", ")} from posts where author_id is null`, | ||
) | ||
: []; | ||
return rawUserIds.map((userId) => | ||
userId == null || userId < 0 | ||
? anonymousPosts | ||
: posts.filter((f) => f.author_id === userId), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.