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

Refactor materializeWebsite in browser_based_querying #300

Merged
merged 2 commits into from
Jun 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions experiments/browser_based_querying/src/hackernews/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
initialize,
executeQuery,
} from '../../www2/trustfall_wasm';
import debug from "../utils/debug";
import debug from '../utils/debug';
import {
getAskStories,
getBestItems,
Expand Down Expand Up @@ -71,25 +71,25 @@ const _itemPattern = /^https:\/\/news\.ycombinator\.com\/item\?id=(\d+)$/;
const _userPattern = /^https:\/\/news\.ycombinator\.com\/user\?id=(.+)$/;

function materializeWebsite(fetchPort: MessagePort, url: string): Vertex | null {
const itemMatch = url.match(_itemPattern);
let ret: any
if (itemMatch) {
let matcher: RegExpMatchArray | null = null;
let ret: { url: string; __typename: string } | null = null;
if ((matcher = url.match(_itemPattern))) {
obi1kenobi marked this conversation as resolved.
Show resolved Hide resolved
// This is an item.
ret = materializeItem(fetchPort, parseInt(itemMatch[1]));
} else {
const userMatch = url.match(_userPattern);
if (userMatch) {
// This is a user.
ret = materializeUser(fetchPort, userMatch[1]);
} else {
// This is some other type of webpage that we don't have a more specific type for.
ret = {
__typename: 'Website'
};
const item = materializeItem(fetchPort, parseInt(matcher[1]));
if (item != null) {
ret = { url, ...item };
}
} else if ((matcher = url.match(_userPattern))) {
// This is a user.
const user = materializeUser(fetchPort, matcher[1]);
if (user != null) {
ret = { url, ...user };
}
} else {
ret = { url, __typename: 'Website' };
}
ret.url = url
return ret

return ret;
}

function* linksInHnMarkup(fetchPort: MessagePort, hnText: string | null): IterableIterator<Vertex> {
Expand Down Expand Up @@ -230,7 +230,7 @@ export class MyAdapter implements Adapter<Vertex> {
break;
}
}
yield * resolvePossiblyLimitedIterator(fetcher(this.fetchPort), limit);
yield* resolvePossiblyLimitedIterator(fetcher(this.fetchPort), limit);
} else if (edge === 'User') {
const username = parameters['name'] as string;
const user = materializeUser(this.fetchPort, username);
Expand Down Expand Up @@ -406,11 +406,7 @@ export class MyAdapter implements Adapter<Vertex> {
edge_name: string,
parameters: JsEdgeParameters
): IterableIterator<ContextAndNeighborsIterator<Vertex>> {
if (
type_name === 'Story' ||
type_name === 'Job' ||
type_name === 'Comment'
) {
if (type_name === 'Story' || type_name === 'Job' || type_name === 'Comment') {
if (edge_name === 'link') {
if (type_name === 'Story') {
// Link submission stories have the submitted URL as a link.
Expand Down