Skip to content

Commit

Permalink
Revert [PLAT-254] Remove is_creator usage across protocol (#3475) (#3529
Browse files Browse the repository at this point in the history
)

This reverts commit 1dc64bc.
Causes issues with old client versions that are still relying on is_creator
  • Loading branch information
dylanjeffers authored Jul 22, 2022
1 parent e91d0ef commit 6311d71
Show file tree
Hide file tree
Showing 48 changed files with 604 additions and 244 deletions.
3 changes: 1 addition & 2 deletions discovery-provider/.test.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ audius_delegate_private_key=0x3873ed01bfb13621f9301487cc61326580614a5b99f3c33cf3
audius_solana_rewards_manager_account=8MzNUaBHskteN7poTrZG5wgSNSbXQwieMDB4wk9fgB7f

audius_elasticsearch_url=http://localhost:9200
audius_db_url=postgresql+psycopg2://postgres:postgres@localhost:5432/test_audius_discovery
PROMETHEUS_MULTIPROC_DIR=./prometheus_data
audius_db_url=postgresql+psycopg2://postgres:postgres@localhost:5432/test_audius_discovery

This file was deleted.

1 change: 1 addition & 0 deletions discovery-provider/es-indexer/src/indexers/UserIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class UserIndexer extends BaseIndexer<UserDoc> {
searchable: standardText,
},
},
is_creator: { type: 'boolean' },
is_verified: { type: 'boolean' },
is_deactivated: { type: 'boolean' },
location: { type: 'keyword' },
Expand Down
1 change: 1 addition & 0 deletions discovery-provider/es-indexer/src/types/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ export interface UserRow {
'handle'?: string | null;
'handle_lc'?: string | null;
'has_collectibles'?: boolean;
'is_creator': boolean;
'is_current': boolean;
'is_deactivated'?: boolean;
'is_verified'?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_connect_verified_challenge(app):
handle="TestHandle",
handle_lc="testhandle",
wallet="0x1",
is_creator=False,
is_verified=False,
name="test_name",
created_at=datetime.now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_first_playlist_challenge(app):
handle="TestHandle",
handle_lc="testhandle",
wallet="0x1",
is_creator=False,
is_verified=False,
name="test_name",
created_at=datetime.now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_first_tip_challenge(app):
handle="TestHandle",
handle_lc="testhandle",
wallet="0x1",
is_creator=False,
is_verified=False,
name="test_name",
created_at=datetime.now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def setup_challenges(session):
handle="TestHandle",
handle_lc="testhandle",
wallet="0x1",
is_creator=False,
is_verified=False,
name="test_name",
created_at=datetime.now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_mobile_install_challenge(app):
handle="Referrer",
handle_lc="referrer",
wallet="0x1",
is_creator=False,
is_verified=False,
name="referrer_name",
created_at=datetime.now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_profile_completion_challenge_with_tracks(app):
handle="TestHandle",
handle_lc="testhandle",
wallet="0x123",
is_creator=False,
is_verified=False,
name="test_name",
created_at=datetime.now(),
Expand Down Expand Up @@ -241,6 +242,7 @@ def test_profile_completion_challenge_with_playlists(app):
handle="TestHandle",
handle_lc="testhandle",
wallet="0x123",
is_creator=False,
is_verified=False,
name="test_name",
created_at=datetime.now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def create_user(offset: int) -> User:
handle=f"TestHandle-{offset}",
handle_lc=f"testhandle-{offset}",
wallet="0x1",
is_creator=False,
is_verified=False,
name=f"test_name_{offset}",
created_at=datetime.now(),
Expand Down Expand Up @@ -80,6 +81,7 @@ def test_referral_challenge(app):
handle="Referrer",
handle_lc="referrer",
wallet="0x1",
is_creator=False,
is_verified=False,
name="referrer_name",
created_at=datetime.now(),
Expand Down Expand Up @@ -196,6 +198,7 @@ def test_referral_challenge(app):
handle="VerifiedReferrer",
handle_lc="verifiedreferrer",
wallet="0x1",
is_creator=False,
is_verified=True,
name="referrer_name",
created_at=datetime.now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def setup_db(session):
blocknumber=1,
user_id=1,
is_current=True,
is_creator=True,
wallet="0x38C68fF3926bf4E68289672F75ee1543117dD9B3",
created_at=datetime.now(),
updated_at=datetime.now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def setup_challenges(app):
handle=f"TestHandle{i}",
handle_lc=f"testhandle{i}",
wallet=f"0x{i}",
is_creator=False,
is_verified=False,
name=f"test_name{i}",
created_at=datetime.now(),
Expand All @@ -65,6 +66,7 @@ def setup_challenges(app):
handle=f"TestHandle{i}",
handle_lc=f"testhandle{i}",
wallet=f"0x{i}",
is_creator=False,
is_verified=False,
name=f"test_name{i}",
created_at=datetime.now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ async def test_fetch_metadata(app, mocker):
mock_cid = "QmyEHHWXbES1nOUBIM89eYfsmM25r3Cw7iBpFZyZ9lbfRS"
mock_cid_metadata = {
mock_cid: {
"is_creator": False,
"is_verified": False,
"is_deactivated": False,
"name": "test user name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class TestUserReplicaSetTransaction:
txhash=blessed_user_tx_hash,
user_id=1,
name="tobey maguire",
is_creator=False,
is_current=True,
updated_at=test_timestamp,
created_at=test_timestamp,
Expand All @@ -88,6 +89,7 @@ class TestUserReplicaSetTransaction:
user_id=2,
name="birb",
is_current=None,
is_creator=None,
updated_at=test_timestamp,
created_at=None,
)
Expand Down
35 changes: 35 additions & 0 deletions discovery-provider/integration_tests/tasks/test_index_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ def get_update_name_event():
return event_type, AttrDict({"blockHash": block_hash, "args": update_name_event})


def get_update_is_creator_event():
event_type = user_event_types_lookup["update_is_creator"]
update_is_creator_event = AttrDict({"_userId": 1, "_isCreator": True})
return event_type, AttrDict(
{"blockHash": block_hash, "args": update_is_creator_event}
)


def get_update_creator_node_endpoint_event():
event_type = user_event_types_lookup["update_creator_node_endpoint"]
update_creator_node_endpoint_event = AttrDict(
Expand All @@ -138,6 +146,7 @@ def get_update_creator_node_endpoint_event():
cid_metadata_client = CIDMetadataClient(
{
multihash: {
"is_creator": True,
"is_verified": False,
"name": "raymont",
"handle": "rayjacobson",
Expand Down Expand Up @@ -300,6 +309,28 @@ def test_index_users(bus_mock: mock.MagicMock, app):
# add_user should be updated fields: handle, handle_lc, wallet
assert user_record.location == helpers.bytes32_to_str(entry.args._location)

# ================== Test Update User is Creator Event ==================
event_type, entry = get_update_is_creator_event()

# `is_creator` field is none by default
assert user_record.is_creator == None

parse_user_event(
None, # self - not used
update_task, # only need the ipfs client for get_metadata
session,
None, # tx_receipt - not used
block_number, # not used
entry, # Contains the event args used for updating
event_type, # String that should one of user_event_types_lookup
user_record, # User ORM instance
None, # ipfs_metadata - not used
block_timestamp, # Used to update the user.updated_at field
)

# add_user should be updated fields: handle, handle_lc, wallet
assert user_record.is_creator == entry.args._isCreator

# ================== Test Update User Name Event ==================
event_type, entry = get_update_name_event()

Expand Down Expand Up @@ -571,6 +602,7 @@ def __init__(self):
txhash=blessed_tx_hash,
user_id=91232,
name="tobey maguire",
is_creator=False,
is_current=True,
updated_at=test_timestamp,
created_at=test_timestamp,
Expand All @@ -583,6 +615,7 @@ def __init__(self):
name="birbs",
# Bad fields
is_current=None, # type: ignore
is_creator=None, # type: ignore
updated_at=None, # type: ignore
created_at=None, # type: ignore
)
Expand Down Expand Up @@ -613,6 +646,7 @@ def __init__(self):
[],
[],
[],
[],
[], # second tx receipt
[],
[
Expand All @@ -631,6 +665,7 @@ def __init__(self):
[],
[],
[],
[],
],
autospec=True,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def setup_trending(db):
"user_id": i + 1,
"handle": str(i + 1),
"wallet": str(i + 1),
"is_creator": True,
# Legacy users have profile_picture and cover_photo (versus _sizes)
"profile_picture": "Qm0123456789abcdef0123456789abcdef0123456789ab",
"cover_photo": "Qm0123456789abcdef0123456789abcdef0123456789ab",
Expand Down
1 change: 1 addition & 0 deletions discovery-provider/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def populate_mock_db(db, entities, block_offset=None):
txhash=user_meta.get("txhash", str(i + block_offset)),
user_id=user_meta.get("user_id", i),
is_current=user_meta.get("is_current", True),
is_creator=user_meta.get("is_creator", True),
handle=user_meta.get("handle", str(i)),
handle_lc=user_meta.get("handle", str(i)).lower(),
wallet=user_meta.get("wallet", str(i)),
Expand Down
1 change: 1 addition & 0 deletions discovery-provider/scripts/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def generate_user(user_id, blocknumber):
"is_current": True,
"handle": f"fake_user_{user_id}",
"wallet": f"fake-user-wallet-{user_id}",
"is_creator": True,
"is_verified": random.randrange(0, 5) == 1,
"name": f"Fake User {user_id}",
"updated_at": datetime.now(),
Expand Down
8 changes: 4 additions & 4 deletions discovery-provider/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# Before running this test locally, bring up ipfs pod with libs/scripts/ipfs.sh

source ./scripts/utilities.sh
source .test.env

if [ ! -f .gitignore ]; then
echo "Run test script from audius discovery provider root"
Expand Down Expand Up @@ -74,14 +73,15 @@ docker-compose \
--env-file compose/.test.env \
up -d

# Create prometheus data test dir which is defined
# for tests in the pytest.ini file
mkdir -p $PROMETHEUS_MULTIPROC_DIR
sleep 5

if [ -z ${SKIP_TESTS+x} ]; then
# Unit tests
pytest src

export PROMETHEUS_MULTIPROC_DIR=./prometheus_data
mkdir -p $PROMETHEUS_MULTIPROC_DIR

# Integration tests
pytest integration_tests
fi
1 change: 1 addition & 0 deletions discovery-provider/src/api/v1/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"current_user_followee_follow_count": fields.Integer(required=True),
"does_current_user_follow": fields.Boolean(required=True),
"handle_lc": fields.String(required=True),
"is_creator": fields.Boolean(required=True),
"updated_at": fields.String(required=True),
"cover_photo_sizes": fields.String,
"cover_photo_legacy": fields.String,
Expand Down
1 change: 1 addition & 0 deletions discovery-provider/src/models/users/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class User(Base, RepresentableMixin):
is_current = Column(Boolean, primary_key=True, nullable=False)
handle = Column(String)
wallet = Column(String, index=True)
is_creator = Column(Boolean, nullable=False, server_default=text("false"))
name = Column(Text)
profile_picture = Column(String)
cover_photo = Column(String)
Expand Down
1 change: 1 addition & 0 deletions discovery-provider/src/queries/get_top_genre_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def get_top_genre_users(args):
.join(Track, Track.owner_id == User.user_id)
.filter(
User.is_current == True,
User.is_creator == True,
Track.is_unlisted == False,
Track.stem_of == None,
Track.is_current == True,
Expand Down
5 changes: 5 additions & 0 deletions discovery-provider/src/queries/get_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def get_users_and_ids():

can_use_shared_cache = (
"id" in args
and "is_creator" not in args
and "wallet" not in args
and "min_block_number" not in args
and "handle" not in args
Expand All @@ -42,6 +43,10 @@ def get_users_and_ids():
)

# Process filters
if "is_creator" in args:
base_query = base_query.filter(
User.is_creator == args.get("is_creator")
)
if "wallet" in args:
wallet = args.get("wallet")
wallet = wallet.lower()
Expand Down
4 changes: 3 additions & 1 deletion discovery-provider/src/queries/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ def parse_id_array_param(list):
# ####### ROUTES ####### #

# Returns all users (paginated) with each user's follow count
# Optionally filters by wallet or user ids
# Optionally filters by is_creator, wallet, or user ids
@bp.route("/users", methods=("GET",))
@record_metrics
def get_users_route():
args = to_dict(request.args)
if "is_creator" in request.args:
args["is_creator"] = parse_bool_param(request.args.get("is_creator"))
if "id" in request.args:
args["id"] = parse_id_array_param(request.args.getlist("id"))
if "min_block_number" in request.args:
Expand Down
2 changes: 2 additions & 0 deletions discovery-provider/src/tasks/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ def parse_user_event(
helpers.get_tx_arg(entry, "_coverPhotoDigest")
)
user_record.cover_photo = cover_photo_multihash
elif event_type == user_event_types_lookup["update_is_creator"]:
user_record.is_creator = helpers.get_tx_arg(entry, "_isCreator")
elif event_type == user_event_types_lookup["update_is_verified"]:
user_record.is_verified = helpers.get_tx_arg(entry, "_isVerified")
if user_record.is_verified:
Expand Down
Loading

0 comments on commit 6311d71

Please sign in to comment.