Skip to content

Commit

Permalink
Add support for "User"."mastId"
Browse files Browse the repository at this point in the history
  • Loading branch information
mindlapse committed Feb 4, 2023
1 parent bcb389e commit 7272eb1
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 76 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ build
node_modules
*.js
!jest.config.js
.env.*
!remix.config.js
.env
**/.env.*
!.env.sample
.terraform
.terraform.*
Expand Down
2 changes: 1 addition & 1 deletion functions/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ FROM public.ecr.aws/lambda/nodejs:16.2022.05.31.10
COPY build /var/task/

RUN mkdir /var/task/schema
COPY src/prisma /var/task/prisma
COPY package.json package-lock.json /var/task/

# Install NPM dependencies for function
WORKDIR /var/task
RUN npm ci
COPY prisma /var/task/prisma
RUN npx prisma generate --schema=/var/task/prisma/schema.prisma

# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
Expand Down
2 changes: 1 addition & 1 deletion functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"dependencies": {
"@aws-sdk/client-cloudwatch": "^3.241.0",
"@aws-sdk/client-ssm": "^3.241.0",
"@jest/globals": "^29.3.1",
"@prisma/client": "^4.8.0",
"mastodon-api": "=1.3.0",
"redis": "^4.5.1",
"ts-node": "^10.9.1"
},
"devDependencies": {
"@jest/globals": "^29.3.1",
"@types/jest": "^29.2.5",
"ts-jest": "^29.0.3"
}
Expand Down
69 changes: 69 additions & 0 deletions functions/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
generator client {
provider = "prisma-client-js"
engineType = "binary"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id Int @id @default(autoincrement())
user String @unique
added_on DateTime @db.Date
mastId BigInt @unique
tags UserTag[]
}

model UserTag {
tag String
userId Int
date DateTime @db.Date
id BigInt @id @default(autoincrement())
user User @relation(fields: [userId], references: [id])
@@index([date, tag, userId])
}

model SpicyUser {
user String @unique
added_on DateTime @db.Date
id BigInt @id @default(autoincrement())
}

model Application {
domain String @id
clientId String
clientSecret String
vapidKey String
redirectUris String
}

model ConnectedUser {
mastodonId String @id
authCode String?
connectedOn DateTime @default(now()) @db.Date
domain String
}

model MastodonOAuth {
access_token String
refresh_token DateTime
client_id String @id
}

model OpaqueId {
opaqueId String @id
mastodonId String
createdOn DateTime @default(now()) @db.Date
accessToken String?
}

model SpicyTags {
mastodonId String
tag String
hide Boolean @default(false)
@@id([mastodonId, tag])
}
4 changes: 2 additions & 2 deletions functions/pu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ account_id=`aws sts get-caller-identity --query "Account" --output text`


echo "Building image"
npx tsc && docker build -t ${account_id}.dkr.ecr.${region}.amazonaws.com/${image_name}:latest .
docker build -t ${account_id}.dkr.ecr.${region}.amazonaws.com/${image_name}:latest .

echo "Docker logging in"
aws ecr get-login-password --region ${region} | docker login --username AWS --password-stdin ${account_id}.dkr.ecr.${region}.amazonaws.com
Expand All @@ -52,4 +52,4 @@ then

else
echo "Failed."
fi
fi
2 changes: 1 addition & 1 deletion functions/src/commands/sample_tags/SampleTagsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class SampleTagsCommand {

// Handle each post
for (let post of result.data) {
this.handlePost(post, tagsSampled)
await this.handlePost(post, tagsSampled)
}
return tagsSampled
}
Expand Down
3 changes: 2 additions & 1 deletion functions/src/commands/sample_tags/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const createOnPost = (
) => {
return async (post: any, postTags: Set<string>) => {
const user = post.account.acct as string
const userId = post.account.id

// Ignore posts that were already seen & remember new posts
if (oldPostIds.has(post.id)) return
Expand All @@ -71,6 +72,6 @@ export const createOnPost = (
}

// Save the tags from the post
await tagsSvc.savePostTags(user, postTags)
await tagsSvc.savePostTags(user, userId, postTags)
}
}
32 changes: 0 additions & 32 deletions functions/src/prisma/schema.prisma

This file was deleted.

10 changes: 9 additions & 1 deletion functions/src/spicyTags.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
"climatechange",
"climatecrisis",
"climatedenial",
"climateemergency",
"extinction",
"decarbonisation",
"carbon",
"carbonoffset",
"co2",
"fossilfuels",
"ghg",
"globalwarming",
"hydrogen",
"lithium",
"magnesium",
Expand Down Expand Up @@ -78,6 +81,8 @@
"greatsaltlake",
"bonneville",

"ai",
"ml",
"chatgpt",
"tensorflow",
"pytorch",
Expand All @@ -92,6 +97,7 @@
"serverless",
"fargate",
"lambda",
"programming",
"python",
"rust",
"rustlang",
Expand All @@ -108,6 +114,8 @@
"openai",
"stripe",
"aws",
"openai"
"openai",
"nasa",
"scifi"
]
}
3 changes: 2 additions & 1 deletion functions/src/svc/TagsSvc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class TagsSvc {
/*
Persists the user (if needed) to the DB and saves their tags, for the current date.
*/
async savePostTags(userAddress: string, tags: Set<string>) {
async savePostTags(userAddress: string, mastId: string, tags: Set<string>) {
try {
const date = today()
const prisma = this.pc.getClient()
Expand All @@ -44,6 +44,7 @@ export default class TagsSvc {
data: {
added_on: date,
user: userAddress,
mastId: BigInt(mastId),
tags: {
createMany: {
data: Array.from(tags, (tag) => ({
Expand Down
6 changes: 4 additions & 2 deletions functions/src/svc/cache/RecentPostsCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ export default class RecentPostsCache {
}

async addRecentPostIds(...postIds: string[]) {
await this.rc.lPush(this.key, ...postIds)
await this.rc.lTrim(this.key, RecentPostsCache.MAX_ITEMS)
if (postIds.length > 0) {
await this.rc.lPush(this.key, ...postIds)
await this.rc.lTrim(this.key, RecentPostsCache.MAX_ITEMS)
}
}

async getRecentPostIds(): Promise<Set<string>> {
Expand Down
32 changes: 0 additions & 32 deletions prisma/schema.prisma

This file was deleted.

10 changes: 10 additions & 0 deletions terraform/bootstrap/_provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
provider "aws" {
region = var.region
profile = var.aws_profile
default_tags {
tags = {
product = var.product
env = var.env
}
}
}
1 change: 0 additions & 1 deletion terraform/module_sample_tags.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ module "sample_tags" {
schedule_expression = "rate(3 minutes)"
fifo = false
}

0 comments on commit 7272eb1

Please sign in to comment.