Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
make inbox and admin user posts index more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
tnix100 authored Nov 16, 2024
1 parent 8b7b297 commit 6c3a8e1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
7 changes: 4 additions & 3 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@
db.posts.create_index([
("post_origin", pymongo.ASCENDING),
("isDeleted", pymongo.ASCENDING),
("t.e", pymongo.DESCENDING),
("u", pymongo.ASCENDING)
("t.e", pymongo.DESCENDING)
], name="default")
except: pass
try:
db.posts.create_index([
("u", pymongo.ASCENDING)
("u", pymongo.ASCENDING),
("post_origin", pymongo.ASCENDING),
("t.e", pymongo.DESCENDING)
], name="user")
except: pass
try:
Expand Down
5 changes: 2 additions & 3 deletions rest_api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,8 @@ async def get_user_posts(username, query_args: GetUserPostsQueryArgs):
# Get posts
if query_args.origin:
query = {
"post_origin": query_args.origin,
"$or": [{"isDeleted": False}, {"isDeleted": True}],
"u": username,
"post_origin": query_args.origin
}
else:
query = {"u": username}
Expand Down Expand Up @@ -769,7 +768,7 @@ async def clear_user_posts(username, query_args: ClearUserPostsQueryArgs):

# Delete posts
if query_args.origin:
query = {"post_origin": query_args.origin, "isDeleted": False, "u": username}
query = {"u": username, "post_origin": query_args.origin, "isDeleted": False}
else:
query = {"u": username, "isDeleted": False}
db.posts.update_many(
Expand Down
2 changes: 1 addition & 1 deletion rest_api/v0/inbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def get_inbox_posts(query_args: GetInboxQueryArgs):
abort(401)

# Get and return posts
query = {"post_origin": "inbox", "isDeleted": False, "$or": [{"u": request.user}, {"u": "Server"}]}
query = {"u": {"$or": [request.user, "Server"]}, "post_origin": "inbox", "isDeleted": False}
return {
"error": False,
"autoget": app.supporter.parse_posts_v0(db.posts.find(
Expand Down

0 comments on commit 6c3a8e1

Please sign in to comment.