Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note_extension
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note_extension
Commits
1f2e4944
Commit
1f2e4944
authored
Feb 06, 2026
by
Hoanganhvu123
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: add production-ready MongoDB indexes and clean env files
parent
d12635ed
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
20 deletions
+42
-20
.env
.env
+0
-4
mongo_client.py
backend/common/mongo_client.py
+38
-15
.env
frontend/.env
+4
-1
No files found.
.env
deleted
100644 → 0
View file @
d12635ed
VITE_CLERK_PUBLISHABLE_KEY=pk_test_Y29tbXVuYWwtc3VuYmVhbS0wLmNsZXJrLmFjY291bnRzLmRldiQ
CLERK_SECRET_KEY=sk_test_ek7ozVR80Qi9UdvhGaTmlXovS16GDuBDlDrpH1rkyQ
MONGODB_URI = mongodb+srv://20010841:vuhoanganh1704@cluster0.h6qro.mongodb.net/?appName=Cluster0
\ No newline at end of file
backend/common/mongo_client.py
View file @
1f2e4944
...
...
@@ -155,35 +155,58 @@ def parse_object_id(id_str: str) -> ObjectId | None:
async
def
create_indexes
():
"""Create database indexes for performance optimization."""
"""Create database indexes for performance optimization
(Production-ready)
."""
try
:
db
=
mongodb_client
.
db
# Indexes for memos collection
await
db
[
COLLECTION_MEMOS
]
.
create_index
([(
"user_id"
,
1
),
(
"created_at"
,
-
1
)])
await
db
[
COLLECTION_MEMOS
]
.
create_index
([(
"user_id"
,
1
),
(
"visibility"
,
1
)])
# ====================== MEMOS COLLECTION ======================
# Primary query patterns - creator_id is used extensively
await
db
[
COLLECTION_MEMOS
]
.
create_index
([(
"creator_id"
,
1
),
(
"created_at"
,
-
1
)])
await
db
[
COLLECTION_MEMOS
]
.
create_index
([(
"creator_id"
,
1
),
(
"visibility"
,
1
)])
await
db
[
COLLECTION_MEMOS
]
.
create_index
([(
"creator_id"
,
1
),
(
"pinned"
,
1
)])
await
db
[
COLLECTION_MEMOS
]
.
create_index
([(
"creator_id"
,
1
),
(
"row_status"
,
1
)])
# Lookup by uid (used for memo detail pages)
await
db
[
COLLECTION_MEMOS
]
.
create_index
([(
"uid"
,
1
)],
unique
=
True
,
sparse
=
True
)
# Comments lookup (parent reference)
await
db
[
COLLECTION_MEMOS
]
.
create_index
([(
"parent"
,
1
),
(
"visibility"
,
1
)])
# Tag filtering and date range queries
await
db
[
COLLECTION_MEMOS
]
.
create_index
([(
"tags"
,
1
)])
await
db
[
COLLECTION_MEMOS
]
.
create_index
([(
"created_at"
,
-
1
)])
#
Indexes for memo relations
#
====================== MEMO RELATIONS ======================
await
db
[
COLLECTION_MEMO_RELATIONS
]
.
create_index
([(
"memo_id"
,
1
)])
await
db
[
COLLECTION_MEMO_RELATIONS
]
.
create_index
([(
"related_memo_id"
,
1
)])
#
Indexes for reactions
await
db
[
COLLECTION_REACTIONS
]
.
create_index
([(
"
memo
_id"
,
1
)])
await
db
[
COLLECTION_REACTIONS
]
.
create_index
([(
"
use
r_id"
,
1
)])
#
====================== REACTIONS ======================
await
db
[
COLLECTION_REACTIONS
]
.
create_index
([(
"
content
_id"
,
1
)])
await
db
[
COLLECTION_REACTIONS
]
.
create_index
([(
"
creato
r_id"
,
1
)])
#
Indexes for memo embeddings
await
db
[
COLLECTION_MEMO_EMBEDDINGS
]
.
create_index
([(
"memo_id"
,
1
)])
await
db
[
COLLECTION_MEMO_EMBEDDINGS
]
.
create_index
([(
"
user_id"
,
1
),
(
"date"
,
-
1
)])
#
====================== MEMO EMBEDDINGS ======================
await
db
[
COLLECTION_MEMO_EMBEDDINGS
]
.
create_index
([(
"memo_id"
,
1
)]
,
unique
=
True
,
sparse
=
True
)
await
db
[
COLLECTION_MEMO_EMBEDDINGS
]
.
create_index
([(
"
date_key"
,
1
)])
# Indexes for inbox
await
db
[
COLLECTION_INBOX
]
.
create_index
([(
"user_id"
,
1
),
(
"created_at"
,
-
1
)])
# ====================== INBOX ======================
await
db
[
COLLECTION_INBOX
]
.
create_index
([(
"receiver"
,
1
),
(
"created_at"
,
-
1
)])
await
db
[
COLLECTION_INBOX
]
.
create_index
([(
"receiver"
,
1
),
(
"status"
,
1
)])
#
Indexes for user settings
#
====================== USER SETTINGS ======================
await
db
[
COLLECTION_USER_SETTINGS
]
.
create_index
([(
"user_id"
,
1
)],
unique
=
True
)
logger
.
info
(
"✅ Database indexes created successfully"
)
# ====================== ACTIVITIES ======================
await
db
[
"cuccu_activities"
]
.
create_index
([(
"created_at"
,
-
1
)])
await
db
[
"cuccu_activities"
]
.
create_index
([(
"creator_id"
,
1
)])
# ====================== NOTIFICATIONS ======================
await
db
[
"cuccu_notifications"
]
.
create_index
([(
"recipient_id"
,
1
),
(
"created_at"
,
-
1
)])
await
db
[
"cuccu_notifications"
]
.
create_index
([(
"recipient_id"
,
1
),
(
"status"
,
1
)])
# ====================== MEMO VERSIONS ======================
await
db
[
"cuccu_memo_versions"
]
.
create_index
([(
"memo_id"
,
1
),
(
"version_index"
,
-
1
)])
logger
.
info
(
"✅ Database indexes created successfully (Production-ready)"
)
except
Exception
as
e
:
logger
.
warning
(
f
"⚠️ Error creating indexes (may already exist): {e}"
)
...
...
frontend/.env
View file @
1f2e4944
# ====================== CLERK (PUBLIC KEY ONLY - NO SECRET) ======================
VITE_CLERK_PUBLISHABLE_KEY=pk_test_Y29tbXVuYWwtc3VuYmVhbS0wLmNsZXJrLmFjY291bnRzLmRldiQ
CLERK_SECRET_KEY=sk_test_ek7ozVR80Qi9UdvhGaTmlXovS16GDuBDlDrpH1rkyQ
\ No newline at end of file
# ====================== API URL ======================
VITE_API_URL=http://localhost:8080
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment