-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce a new endpoint for UI metadata (#92)
* feat: introduce a new endpoint for UI meta * rename ext n1ql -> sql for code highlighting * format all sql files * tidy
- Loading branch information
1 parent
e390411
commit e82aa96
Showing
55 changed files
with
713 additions
and
518 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* N1QL query to prepend a username to the user's following. */ | ||
UPDATE `bucket_name` | ||
USE KEYS LOWER($user) | ||
SET | ||
`DYNAMIC_FIELD` = ARRAY_PREPEND( | ||
{"username": $username, "ts": $ts}, | ||
`DYNAMIC_FIELD` | ||
) | ||
WHERE | ||
NOT ANY item IN `DYNAMIC_FIELD` SATISFIES item.username = $username END; |
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,7 @@ | ||
/* N1QL query to prepend a liked file from a user's likes. */ | ||
UPDATE `bucket_name` | ||
USE KEYS $user | ||
SET | ||
likes = ARRAY_PREPEND({"sha256": $sha256, "ts": $ts}, likes) | ||
WHERE | ||
NOT ANY item IN likes SATISFIES item.sha256 = $sha256 END; |
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,7 @@ | ||
/* N1QL query to remove a user from a user's following. */ | ||
UPDATE `bucket_name` | ||
USE KEYS LOWER($user) | ||
SET | ||
`DYNAMIC_FIELD` = ARRAY item FOR item IN `DYNAMIC_FIELD` WHEN item.username != $username END | ||
WHERE | ||
ANY item IN `DYNAMIC_FIELD` SATISFIES item.username = $username END; |
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,7 @@ | ||
/* N1QL query to remove a liked file from a user's likes. */ | ||
UPDATE `bucket_name` | ||
USE KEYS $user | ||
SET | ||
likes = ARRAY like_item FOR like_item IN likes WHEN like_item.sha256 != $sha256 END | ||
WHERE | ||
ANY like_item IN likes SATISFIES like_item.sha256 = $sha256 END; |
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,64 @@ | ||
/* N1QL query to retrieve activities for an anonymous user. */ | ||
WITH | ||
activity_data AS ( | ||
SELECT | ||
activity.kind, | ||
META(activity).id AS activity_id, | ||
activity.username, | ||
activity.timestamp, | ||
activity.target | ||
FROM | ||
`bucket_name` AS activity | ||
WHERE | ||
activity.type = 'activity' | ||
AND activity.src = "web" | ||
AND activity.kind != "comment" | ||
ORDER BY | ||
activity.timestamp DESC | ||
OFFSET | ||
$offset | ||
LIMIT | ||
$limit | ||
) | ||
SELECT | ||
{ | ||
"type": activity.kind, | ||
"id": activity.activity_id, | ||
"author": { | ||
"username": activity.username, | ||
"member_since": ( | ||
SELECT | ||
RAW u.member_since | ||
FROM | ||
`bucket_name` AS u | ||
USE KEYS LOWER(activity.username) | ||
) [0] | ||
}, | ||
"follow": false, | ||
"date": activity.timestamp | ||
}.*, | ||
( | ||
CASE | ||
WHEN activity.kind = "follow" THEN {"target": activity.target} | ||
ELSE { | ||
"file": { | ||
"hash": f.sha256, | ||
"tags": f.tags, | ||
"filename": f.submissions[0].filename, | ||
"class": f.ml.pe.predicted_class, | ||
"multiav": { | ||
"value": ARRAY_COUNT( | ||
ARRAY_FLATTEN( | ||
ARRAY i.infected FOR i IN OBJECT_VALUES(f.multiav.last_scan) WHEN i.infected = TRUE END, | ||
1 | ||
) | ||
), | ||
"count": OBJECT_LENGTH(f.multiav.last_scan) | ||
} | ||
} | ||
} | ||
END | ||
).* | ||
FROM | ||
activity_data AS activity | ||
LEFT JOIN `bucket_name` AS f ON KEYS activity.target; |
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,35 @@ | ||
/* N1QL query to retrieve user's comments for an anonymous user. */ | ||
SELECT | ||
{ | ||
"id": META(c).id, | ||
"comment": c.body, | ||
"liked": false, | ||
"date": c.timestamp, | ||
"file": { | ||
"hash": f.sha256, | ||
"tags": f.tags, | ||
"filename": f.submissions[0].filename, | ||
"class": f.ml.pe.predicted_class, | ||
"multiav": { | ||
"value": ARRAY_COUNT( | ||
ARRAY_FLATTEN( | ||
ARRAY i.infected FOR i IN OBJECT_VALUES(f.multiav.last_scan) WHEN i.infected = TRUE END, | ||
1 | ||
) | ||
), | ||
"count": OBJECT_LENGTH(f.multiav.last_scan) | ||
} | ||
} | ||
}.* | ||
FROM | ||
`bucket_name` c | ||
LEFT JOIN `bucket_name` f ON KEYS c.sha256 | ||
WHERE | ||
c.`type` = 'comment' | ||
AND c.`username` = $user | ||
ORDER BY | ||
c.timestamp DESC | ||
OFFSET | ||
$offset | ||
LIMIT | ||
$limit |
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,23 @@ | ||
/* N1QL query to retrieve user followers for an anonymous user. */ | ||
SELECT | ||
RAW { | ||
"id": META(p).id, | ||
"username": p.`username`, | ||
"member_since": p.`member_since`, | ||
"follow": FALSE | ||
} | ||
FROM | ||
`bucket_name` p | ||
USE KEYS [ | ||
( | ||
SELECT | ||
RAW ARRAY LOWER(u.username) FOR u IN s.`followers` END | ||
FROM | ||
`bucket_name` s | ||
USE KEYS $user | ||
) [0] | ||
] | ||
OFFSET | ||
$offset | ||
LIMIT | ||
$limit |
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,23 @@ | ||
/* N1QL query to retrieve users' following for an anonymous user. */ | ||
SELECT | ||
RAW { | ||
"id": META(p).id, | ||
"username": p.`username`, | ||
"member_since": p.`member_since`, | ||
"follow": FALSE | ||
} | ||
FROM | ||
`bucket_name` p | ||
USE KEYS [ | ||
( | ||
SELECT | ||
RAW ARRAY LOWER(u.username) FOR u IN s.`following` END | ||
FROM | ||
`bucket_name` s | ||
USE KEYS $user | ||
) [0] | ||
] | ||
OFFSET | ||
$offset | ||
LIMIT | ||
$limit |
Oops, something went wrong.