Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

pointer: Remove pointer from UserProfile.

Steve Howell0b65abcdf54e
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index 9aec5de310f..97cd5940832 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -1154,8 +1154,8 @@ class StripeTest(StripeTestCase):
def test_get_latest_seat_count(self) -> None:
realm = get_realm("zulip")
initial_count = get_latest_seat_count(realm)
- user1 = UserProfile.objects.create(realm=realm, email='[email protected]', pointer=-1)
- user2 = UserProfile.objects.create(realm=realm, email='[email protected]', pointer=-1)
+ user1 = UserProfile.objects.create(realm=realm, email='[email protected]')
+ user2 = UserProfile.objects.create(realm=realm, email='[email protected]')
self.assertEqual(get_latest_seat_count(realm), initial_count + 2)
# Test that bots aren't counted
@@ -1169,17 +1169,17 @@ class StripeTest(StripeTestCase):
# Test guests
# Adding a guest to a realm with a lot of members shouldn't change anything
- UserProfile.objects.create(realm=realm, email='[email protected]', pointer=-1, role=UserProfile.ROLE_GUEST)
+ UserProfile.objects.create(realm=realm, email='[email protected]', role=UserProfile.ROLE_GUEST)
self.assertEqual(get_latest_seat_count(realm), initial_count)
# Test 1 member and 5 guests
realm = Realm.objects.create(string_id='second', name='second')
- UserProfile.objects.create(realm=realm, email='[email protected]', pointer=-1)
+ UserProfile.objects.create(realm=realm, email='[email protected]')
for i in range(5):
UserProfile.objects.create(realm=realm, email=f'guest{i}@second.com',
- pointer=-1, role=UserProfile.ROLE_GUEST)
+ role=UserProfile.ROLE_GUEST)
self.assertEqual(get_latest_seat_count(realm), 1)
# Test 1 member and 6 guests
- UserProfile.objects.create(realm=realm, email='[email protected]', pointer=-1,
+ UserProfile.objects.create(realm=realm, email='[email protected]',
role=UserProfile.ROLE_GUEST)
self.assertEqual(get_latest_seat_count(realm), 2)
diff --git a/zerver/data_import/gitter.py b/zerver/data_import/gitter.py
index 60acfbec7df..c407985cf9b 100644
--- a/zerver/data_import/gitter.py
+++ b/zerver/data_import/gitter.py
@@ -94,7 +94,6 @@ def build_userprofile(timestamp: Any, domain_name: str,
email=email,
delivery_email=email,
avatar_source='U',
- pointer=-1,
date_joined=timestamp,
last_login=timestamp)
userprofile_dict = model_to_dict(userprofile)
diff --git a/zerver/data_import/import_util.py b/zerver/data_import/import_util.py
index ce368601bfb..1352e485657 100644
--- a/zerver/data_import/import_util.py
+++ b/zerver/data_import/import_util.py
@@ -88,7 +88,6 @@ def build_user_profile(avatar_source: str,
realm_id: int,
short_name: str,
timezone: Optional[str]) -> ZerverFieldsT:
- pointer = -1
obj = UserProfile(
avatar_source=avatar_source,
date_joined=date_joined,
@@ -99,7 +98,6 @@ def build_user_profile(avatar_source: str,
is_mirror_dummy=is_mirror_dummy,
is_active=is_active,
role=role,
- pointer=pointer,
realm_id=realm_id,
short_name=short_name,
timezone=timezone,
diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.py
index 26190b5095e..5cf2186f730 100755
--- a/zerver/data_import/slack.py
+++ b/zerver/data_import/slack.py
@@ -214,7 +214,6 @@ def users_to_zerver_userprofile(slack_data_dir: str, users: List[ZerverFieldsT],
delivery_email=email,
avatar_source='U',
is_bot=user.get('is_bot', False),
- pointer=-1,
role=role,
bot_type=1 if user.get('is_bot', False) else None,
date_joined=timestamp,
diff --git a/zerver/lib/create_user.py b/zerver/lib/create_user.py
index 618b8e4362e..457da0552dd 100644
--- a/zerver/lib/create_user.py
+++ b/zerver/lib/create_user.py
@@ -79,7 +79,7 @@ def create_user_profile(realm: Realm, email: str, password: Optional[str],
user_profile = UserProfile(is_staff=False, is_active=active,
full_name=full_name, short_name=short_name,
last_login=now, date_joined=now, realm=realm,
- pointer=-1, is_bot=bool(bot_type), bot_type=bot_type,
+ is_bot=bool(bot_type), bot_type=bot_type,
bot_owner=bot_owner, is_mirror_dummy=is_mirror_dummy,
tos_version=tos_version, timezone=timezone,
tutorial_status=tutorial_status,
diff --git a/zerver/lib/import_realm.py b/zerver/lib/import_realm.py
index 333a4626dc9..c7c1768862e 100644
--- a/zerver/lib/import_realm.py
+++ b/zerver/lib/import_realm.py
@@ -1045,30 +1045,6 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int=1) -> Realm
update_model_ids(Reaction, data, 'reaction')
bulk_import_model(data, Reaction)
- for user_profile in UserProfile.objects.filter(is_bot=False, realm=realm):
- # Since we now unconditionally renumbers message IDs, we need
- # to reset the user's pointer to what will be a valid value.
- #
- # For zulip->zulip imports, we could do something clever, but
- # it should always be safe to reset to first unread message.
- #
- # Longer-term, the plan is to eliminate pointer as a concept.
- first_unread_message = UserMessage.objects.filter(user_profile=user_profile).extra(
- where=[UserMessage.where_unread()],
- ).order_by("message_id").first()
- if first_unread_message is not None:
- user_profile.pointer = first_unread_message.message_id
- else:
- last_message = UserMessage.objects.filter(
- user_profile=user_profile).order_by("message_id").last()
- if last_message is not None:
- user_profile.pointer = last_message.message_id
- else:
- # -1 is the guard value for new user accounts with no messages.
- user_profile.pointer = -1
-
- user_profile.save(update_fields=["pointer"])
-
# Similarly, we need to recalculate the first_message_id for stream objects.
for stream in Stream.objects.filter(realm=realm):
recipient = Recipient.objects.get(type=Recipient.STREAM, type_id=stream.id)
diff --git a/zerver/migrations/0294_remove_userprofile_pointer.py b/zerver/migrations/0294_remove_userprofile_pointer.py
new file mode 100644
index 00000000000..623444e6ef5
--- /dev/null
+++ b/zerver/migrations/0294_remove_userprofile_pointer.py
@@ -0,0 +1,17 @@
+# Generated by Django 2.2.13 on 2020-07-03 12:53
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('zerver', '0293_update_invite_as_dict_values'),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name='userprofile',
+ name='pointer',
+ ),
+ ]
diff --git a/zerver/models.py b/zerver/models.py
index b6f0fc89271..e414f13c4ed 100644
--- a/zerver/models.py
+++ b/zerver/models.py
@@ -900,9 +900,6 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
tos_version: Optional[str] = models.CharField(null=True, max_length=10)
api_key: str = models.CharField(max_length=API_KEY_LENGTH)
- # pointer points to Message.id, NOT UserMessage.id.
- pointer: int = models.IntegerField()
-
# Whether the user has access to server-level administrator pages, like /activity
is_staff: bool = models.BooleanField(default=False)
diff --git a/zerver/tests/test_messages.py b/zerver/tests/test_messages.py
index 73ad25c595d..6790f3e0a87 100644
--- a/zerver/tests/test_messages.py
+++ b/zerver/tests/test_messages.py
@@ -971,7 +971,6 @@ class StreamMessagesTest(ZulipTestCase):
user = UserProfile.objects.create(
realm=realm,
email=email,
- pointer=0,
long_term_idle=long_term_idle,
)
Subscription.objects.create(