···
10
+
_ "github.com/lib/pq"
14
+
postURI = "at://did:plc:hcuo3qx2lr7h7dquusbeobht/social.coves.community.post/3m56mowhbuk22"
15
+
postCID = "bafyreibml4midgt7ojq7dnabnku5ikzro4erfvdux6mmiqeat7pci2gy4u"
16
+
communityDID = "did:plc:hcuo3qx2lr7h7dquusbeobht"
25
+
type Comment struct {
38
+
// Escalating conversation between two users
39
+
var deepThreadConversation = []string{
40
+
"Wait, I just realized - if they both get suspended for this, their fantasy managers are SCREWED 😂",
41
+
"Bro imagine being in a league where you have BOTH Duren brothers and they both get suspended for fighting EACH OTHER",
42
+
"That's actually hilarious. 'Dear commissioner, my players got suspended for fighting... with each other'",
43
+
"The fantasy implications are wild. Do you get negative points for your players fighting your other players? 🤔",
44
+
"New fantasy category: Family Feuds. Duren brothers leading the league in FFD (Family Fight Disqualifications)",
45
+
"I'm dying 💀 FFD should absolutely be a stat. The Morris twins would've been unstoppable in that category",
46
+
"Don't forget the Plumlees! Those boys used to scrap in college practices. FFD Hall of Famers",
47
+
"Okay but serious question: has there EVER been brothers fighting each other in an NBA game before this? This has to be a first",
48
+
"I've been watching the NBA for 30 years and I can't think of a single time. This might genuinely be historic family beef",
49
+
"So we're witnessing NBA history right now. Not the good kind, but history nonetheless. Their mom is SO proud 😂",
52
+
var userHandles = []string{
53
+
"deep_thread_guy_1.bsky.social",
54
+
"deep_thread_guy_2.bsky.social",
57
+
func generateTID() string {
58
+
now := time.Now().UnixMicro()
59
+
return fmt.Sprintf("%d%04d", now, rand.Intn(10000))
62
+
func createUser(db *sql.DB, handle string, idx int) (*User, error) {
63
+
did := fmt.Sprintf("did:plc:deepthread%d%d", time.Now().Unix(), idx)
71
+
INSERT INTO users (did, handle, pds_url, created_at, updated_at)
72
+
VALUES ($1, $2, $3, NOW(), NOW())
73
+
ON CONFLICT (did) DO NOTHING
76
+
_, err := db.Exec(query, user.DID, user.Handle, "http://localhost:3001")
78
+
return nil, fmt.Errorf("failed to create user: %w", err)
81
+
log.Printf("Created user: %s (%s)", user.Handle, user.DID)
85
+
func createComment(db *sql.DB, user *User, content, parentURI, parentCID string, createdAt time.Time) (*Comment, error) {
86
+
rkey := generateTID()
87
+
uri := fmt.Sprintf("at://%s/social.coves.feed.comment/%s", user.DID, rkey)
88
+
cid := fmt.Sprintf("bafy%s", rkey)
90
+
comment := &Comment{
97
+
ParentURI: parentURI,
98
+
ParentCID: parentCID,
100
+
CreatedAt: createdAt,
104
+
INSERT INTO comments (
105
+
uri, cid, rkey, commenter_did, root_uri, root_cid,
106
+
parent_uri, parent_cid, content, created_at, indexed_at
107
+
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, NOW())
108
+
ON CONFLICT (uri) DO NOTHING
113
+
err := db.QueryRow(query,
114
+
comment.URI, comment.CID, comment.RKey, comment.DID,
115
+
comment.RootURI, comment.RootCID, comment.ParentURI, comment.ParentCID,
116
+
comment.Content, comment.CreatedAt,
119
+
return nil, fmt.Errorf("failed to create comment: %w", err)
122
+
log.Printf("Level %d: %s", getCurrentLevel(parentURI), content)
123
+
return comment, nil
126
+
func getCurrentLevel(parentURI string) int {
127
+
if parentURI == postURI {
130
+
// Count how many times we've nested (rough estimate)
131
+
return 2 // Will be incremented as we go
134
+
func updateCommentCount(db *sql.DB, parentURI string, isPost bool) error {
136
+
_, err := db.Exec(`
138
+
SET comment_count = comment_count + 1
144
+
_, err := db.Exec(`
146
+
SET reply_count = reply_count + 1
153
+
dbURL := "postgres://dev_user:dev_password@localhost:5435/coves_dev?sslmode=disable"
154
+
db, err := sql.Open("postgres", dbURL)
156
+
log.Fatalf("Failed to connect to database: %v", err)
160
+
if err := db.Ping(); err != nil {
161
+
log.Fatalf("Failed to ping database: %v", err)
164
+
log.Println("Connected to database successfully!")
165
+
log.Println("Creating 10-level deep comment thread...")
167
+
rand.Seed(time.Now().UnixNano())
169
+
// Create two users who will have the back-and-forth
170
+
user1, err := createUser(db, userHandles[0], 1)
172
+
log.Fatalf("Failed to create user 1: %v", err)
175
+
user2, err := createUser(db, userHandles[1], 2)
177
+
log.Fatalf("Failed to create user 2: %v", err)
180
+
baseTime := time.Now().Add(-30 * time.Minute)
182
+
// Create the 10-level deep thread
183
+
parentURI := postURI
184
+
parentCID := postCID
187
+
for i, content := range deepThreadConversation {
188
+
// Alternate between users
194
+
createdAt := baseTime.Add(time.Duration(i*2) * time.Minute)
196
+
comment, err := createComment(db, user, content, parentURI, parentCID, createdAt)
198
+
log.Fatalf("Failed to create comment at level %d: %v", i+1, err)
201
+
// Update parent's reply count
202
+
if err := updateCommentCount(db, parentURI, isPost); err != nil {
203
+
log.Printf("Warning: Failed to update comment count: %v", err)
206
+
// Set this comment as the parent for the next iteration
207
+
parentURI = comment.URI
208
+
parentCID = comment.CID
211
+
time.Sleep(10 * time.Millisecond)
214
+
log.Println("\n=== Summary ===")
215
+
log.Printf("Created 10-level deep comment thread")
216
+
log.Printf("Thread participants: %s and %s", user1.Handle, user2.Handle)
217
+
log.Println("Done! Check the NBACentral post for the deep thread.")