-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add impressions worker (#3972)
- Loading branch information
Showing
25 changed files
with
255 additions
and
956 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 |
---|---|---|
@@ -1,33 +1,27 @@ | ||
const postsEndpoint = 'https://ens.hey.xyz'; | ||
const postsVisibilityInterval = 5000; | ||
let visiblePostsSet = new Set(); | ||
const impressionsEndpoint = 'https://impressions.hey.xyz/ingest'; | ||
const publicationsVisibilityInterval = 5000; | ||
let visiblePublicationsSet = new Set(); | ||
|
||
function sendVisiblePostsToServer() { | ||
const postsToSend = Array.from(visiblePostsSet); | ||
function sendVisiblePublicationsToServer() { | ||
const publicationsToSend = Array.from(visiblePublicationsSet); | ||
|
||
if (postsToSend.length > 0) { | ||
visiblePostsSet.clear(); | ||
fetch(postsEndpoint, { | ||
if (publicationsToSend.length > 0) { | ||
visiblePublicationsSet.clear(); | ||
fetch(impressionsEndpoint, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ visiblePosts: postsToSend }), | ||
body: JSON.stringify({ ids: publicationsToSend }), | ||
keepalive: true | ||
}) | ||
.then((response) => { | ||
if (!response.ok) { | ||
console.error('Failed to send visible posts:', response); | ||
} | ||
}) | ||
.catch((error) => { | ||
console.error('Error sending visible posts:', error); | ||
}); | ||
.then(() => {}) | ||
.catch(() => {}); | ||
} | ||
} | ||
|
||
setInterval(sendVisiblePostsToServer, postsVisibilityInterval); | ||
setInterval(sendVisiblePublicationsToServer, publicationsVisibilityInterval); | ||
|
||
self.addEventListener('message', (event) => { | ||
if (event.data && event.data.type === 'POST_VISIBLE') { | ||
visiblePostsSet.add(event.data.postId); | ||
if (event.data && event.data.type === 'PUBLICATION_VISIBLE') { | ||
visiblePublicationsSet.add(event.data.id); | ||
} | ||
}); |
35 changes: 1 addition & 34 deletions
35
apps/web/src/components/Common/Providers/LeafwatchProvider.tsx
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 was deleted.
Oops, something went wrong.
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
File renamed without changes.
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.
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,15 @@ | ||
# Impressions worker | ||
|
||
## Clickhouse Schema | ||
|
||
```sql | ||
CREATE TABLE impressions ( | ||
id UUID, | ||
viewer_id String, | ||
publication_id String, | ||
viewed_at DateTime64(3, 'UTC') DEFAULT now64(3) | ||
) ENGINE = MergeTree() | ||
PARTITION BY toYYYYMM(viewed_at) | ||
ORDER BY (viewer_id, publication_id, viewed_at) | ||
SETTINGS index_granularity = 8192; | ||
``` |
Oops, something went wrong.
71473bb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
prerender – ./apps/prerender
prerender-heyxyz.vercel.app
prerender-git-main-heyxyz.vercel.app
prerender.hey.xyz
71473bb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
web – ./apps/web
web-git-main-heyxyz.vercel.app
heyxyz.vercel.app
hey.xyz
web-heyxyz.vercel.app