Skip to content

Commit

Permalink
Promote verified profiles (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
duogenesis authored Jan 5, 2025
1 parent 0ebbc6b commit 8c66f8b
Show file tree
Hide file tree
Showing 14 changed files with 435 additions and 63 deletions.
1 change: 0 additions & 1 deletion DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Install these:
* Docker Compose
* jq
* curl
* ImageMagick
* ffmpeg

Then run this:
Expand Down
29 changes: 25 additions & 4 deletions migrations.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
-- TODO: Delete
CREATE INDEX IF NOT EXISTS idx__messaged__object_person_id__subject_person_id__created_at
ON messaged(object_person_id, subject_person_id, created_at);
-- TODO: Delete this and its associated test

DROP INDEX IF EXISTS idx__messaged__object_person_id__subject_person_id;
UPDATE
person
SET
verification_level_id =
CASE
WHEN
EXISTS (
SELECT
1
FROM
photo
WHERE
person_id = person.id
AND
verified
)
THEN
3

ELSE
2
END
WHERE
verification_level_id <> 1
11 changes: 7 additions & 4 deletions service/person/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,7 @@ def delete_profile_info(req: t.DeleteProfileInfo, s: t.SessionInfo):
if files_params:
with api_tx() as tx:
tx.executemany(Q_DELETE_PROFILE_INFO_PHOTO, files_params)
tx.execute(Q_UPDATE_VERIFICATION_LEVEL, files_params[0])

if audio_files_params:
with api_tx() as tx:
Expand Down Expand Up @@ -1808,10 +1809,8 @@ def get_admin_delete_photo_link(token: str):

try:
with api_tx('READ COMMITTED') as tx:
rows = tx.execute(
Q_CHECK_ADMIN_DELETE_PHOTO_TOKEN,
params
).fetchall()
tx.execute(Q_CHECK_ADMIN_DELETE_PHOTO_TOKEN, params)
rows = tx.fetchall()
except psycopg.errors.InvalidTextRepresentation:
return 'Invalid token', 401

Expand All @@ -1827,6 +1826,10 @@ def get_admin_delete_photo(token: str):
with api_tx('READ COMMITTED') as tx:
rows = tx.execute(Q_ADMIN_DELETE_PHOTO, params).fetchall()

if rows:
params = dict(person_id=rows[0]['person_id'])
tx.execute(Q_UPDATE_VERIFICATION_LEVEL, params)

if rows:
return f'Deleted photo {rows}'
else:
Expand Down
25 changes: 18 additions & 7 deletions service/person/sql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2407,17 +2407,28 @@
WHERE
photo.uuid = deleted_token.photo_uuid
RETURNING
photo.uuid
)
INSERT INTO undeleted_photo (
uuid
photo.uuid,
photo.person_id
), inserted_undeleted_photo AS (
INSERT INTO undeleted_photo (
uuid
)
SELECT
uuid
FROM
deleted_photo
RETURNING
uuid
)
SELECT
uuid
inserted_undeleted_photo.uuid,
deleted_photo.person_id
FROM
inserted_undeleted_photo
JOIN
deleted_photo
RETURNING
uuid
ON
inserted_undeleted_photo.uuid = deleted_photo.uuid
"""

Q_STATS = """
Expand Down
60 changes: 56 additions & 4 deletions service/search/sql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
coordinates,
personality,
gender_id,
verification_level_id,
COALESCE(
(
SELECT
Expand Down Expand Up @@ -523,11 +524,28 @@
ORDER BY
-- If this is changed, other subqueries will need changing too
(has_profile_picture_id = 1) DESC,
verified DESC,
match_percentage DESC
LIMIT
500
), do_promote_verified AS (
SELECT
has_minimum_count.x
AND
searcher.verification_level_id > 1 AS x
FROM
searcher,
(
SELECT
count(*) >= 250 AS x
FROM
prospects_fourth_pass
WHERE
profile_photo_uuid IS NOT NULL
AND
verified
) AS has_minimum_count
)
INSERT INTO search_cache (
searcher_person_id,
Expand All @@ -546,7 +564,14 @@
ROW_NUMBER() OVER (
ORDER BY
-- If this is changed, other subqueries will need changing too
(profile_photo_uuid IS NOT NULL) DESC,
CASE
WHEN (SELECT x FROM do_promote_verified)
THEN
profile_photo_uuid IS NOT NULL AND verified
ELSE
profile_photo_uuid IS NOT NULL
END DESC,
match_percentage DESC
) AS position,
prospect_person_id,
Expand Down Expand Up @@ -681,12 +706,32 @@
Q_QUIZ_SEARCH = """
WITH searcher AS (
SELECT
personality
personality,
verification_level_id
FROM
person
WHERE
person.id = %(searcher_person_id)s
LIMIT 1
), do_promote_verified AS (
SELECT
has_minimum_count.x
AND
searcher.verification_level_id > 1 AS x
FROM
searcher,
(
SELECT
count(*) >= 250 AS x
FROM
search_cache
WHERE
searcher_person_id = %(searcher_person_id)s
AND
profile_photo_uuid IS NOT NULL
AND
verified
) AS has_minimum_count
), page AS (
SELECT
prospect_person_id,
Expand Down Expand Up @@ -724,7 +769,14 @@
searcher_person_id = %(searcher_person_id)s
ORDER BY
-- If this is changed, other subqueries will need changing too
(profile_photo_uuid IS NOT NULL) DESC,
CASE
WHEN (SELECT x FROM do_promote_verified)
THEN
profile_photo_uuid IS NOT NULL AND verified
ELSE
profile_photo_uuid IS NOT NULL
END DESC,
match_percentage DESC
LIMIT
1
Expand Down
2 changes: 1 addition & 1 deletion test/functionality1/gender-stats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ set -xe
response=$(c GET /gender-stats)

[[ $(jq -r '.gender_ratio' <<< "$response") = '0.5' ]]
[[ $(jq -r '.non_binary_percentage' <<< "$response") = '25' ]]
[[ $(jq -r '.non_binary_percentage' <<< "$response") = '25.0' ]]
102 changes: 102 additions & 0 deletions test/functionality1/migration-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env bash

# This test is mostly intended to verify that the `verificationjobrunner` runs
# the jobs. The unit tests for the `verification` Python module are much
# more in-depth.

script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
cd "$script_dir"

source ../util/setup.sh

set -xe

q "delete from person"

../util/create-user.sh user1 0 0
../util/create-user.sh user2 0 0
../util/create-user.sh user3 0 1
../util/create-user.sh user4 0 1


echo Set up user 1
q "
update
person
set
verified_age = false,
verified_gender = false,
verification_level_id = 1
where
name = 'user1'
"

echo Set up user 2
q "
update
person
set
verified_age = true,
verified_gender = true,
verification_level_id = 2
where
name = 'user2'
"


echo Set up user 3
q "
update
person
set
verified_age = true,
verified_gender = true,
verification_level_id = 2
where
name = 'user3'
"

q "
update
photo
set
verified = true
where
person_id in (select id from person where name = 'user3')
"

echo Set up user 4
q "
update
person
set
verified_age = true,
verified_gender = true,
verification_level_id = 3
where
name = 'user4'
"

q "
update
photo
set
verified = false
where
person_id in (select id from person where name = 'user4')
"

q "$(cat ../../migrations.sql)"

verification_level_ids=$(
q "
select
verification_level_id
from
person
order by
name
" | xargs # Neatens whitespace
)

[[ "$verification_level_ids" = '1 2 3 2' ]]
36 changes: 34 additions & 2 deletions test/functionality1/profile-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ test_verification_loss_ethnicity () {
where uuid = '$USER_UUID' and not verified_ethnicity")" -eq 1 ]]
}
test_verification_loss_photo () {
test_verification_loss_photo_changed () {
jc PATCH /profile-info \
-d "{
\"base64_file\": {
Expand Down Expand Up @@ -271,6 +271,37 @@ test_verification_loss_photo () {
where uuid = '$USER_UUID' and verification_level_id = 2")" -eq 1 ]]
}
test_verification_loss_photo_removed () {
jc PATCH /profile-info \
-d "{
\"base64_file\": {
\"position\": 1,
\"base64\": \"${img1}\",
\"top\": 0,
\"left\": 0
}
}"
q "update photo set verified = TRUE"
q "
update person
set verified_age = true,
verified_gender = true,
verification_level_id = 3"
[[ "$(q "select COUNT(*) from photo where verified")" -eq 1 ]]
[[ "$(q "
select COUNT(*) from person \
where uuid = '$USER_UUID' and verification_level_id = 3")" -eq 1 ]]
jc DELETE /profile-info -d '{ "files": [1] }'
[[ "$(q "select COUNT(*) from photo where verified")" -eq 0 ]]
[[ "$(q "
select COUNT(*) from person \
where uuid = '$USER_UUID' and verification_level_id = 2")" -eq 1 ]]
}
test_set name "Jeff"
test_set about "I'm a bad ass motherfuckin' DJ / This is why I walk and talk this way"
test_set gender Woman
Expand Down Expand Up @@ -309,4 +340,5 @@ test_theme
test_verification_loss_gender
test_verification_loss_ethnicity
test_verification_loss_photo
test_verification_loss_photo_changed
test_verification_loss_photo_removed
4 changes: 2 additions & 2 deletions test/functionality1/prospect-profile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ gives_reply_percentage=$(
c GET /prospect-profile/$user2_uuid \
| jq '.gives_reply_percentage')

[[ "$gets_reply_percentage" = '20' ]]
[[ "$gets_reply_percentage" = '20.0' ]]

[[ "$gives_reply_percentage" = 'null' ]]

Expand Down Expand Up @@ -213,4 +213,4 @@ gives_reply_percentage=$(

[[ "$gets_reply_percentage" = 'null' ]]

[[ "$gives_reply_percentage" = '20' ]]
[[ "$gives_reply_percentage" = '20.0' ]]
Loading

0 comments on commit 8c66f8b

Please sign in to comment.