Skip to content

Commit

Permalink
UI/Domains Refactor
Browse files Browse the repository at this point in the history
Redoes the UI to remove timelines, promote domains, and a lot of other things to support the refactor.
  • Loading branch information
andrewgodwin authored May 4, 2023
1 parent 7331591 commit 8f57aa5
Show file tree
Hide file tree
Showing 135 changed files with 1,957 additions and 2,372 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ jobs:
python-version: ["3.10", "3.11"]
db:
- "postgres://postgres:postgres@localhost/postgres"
- "sqlite:///takahe.db"
include:
- db: "postgres://postgres:postgres@localhost/postgres"
db_name: postgres
search: true
- db: "sqlite:///takahe.db"
db_name: sqlite
search: false
services:
postgres:
image: postgres:15
Expand Down
24 changes: 24 additions & 0 deletions activities/migrations/0014_post_content_vector_gin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2 on 2023-04-29 18:49

import django.contrib.postgres.indexes
import django.contrib.postgres.search
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("activities", "0013_postattachment_author"),
]

operations = [
migrations.AddIndex(
model_name="post",
index=django.contrib.postgres.indexes.GinIndex(
django.contrib.postgres.search.SearchVector(
"content", config="english"
),
name="content_vector_gin",
),
),
]
5 changes: 5 additions & 0 deletions activities/models/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import urlman
from asgiref.sync import async_to_sync, sync_to_async
from django.contrib.postgres.indexes import GinIndex
from django.contrib.postgres.search import SearchVector
from django.db import models, transaction
from django.template import loader
from django.template.defaultfilters import linebreaks_filter
Expand Down Expand Up @@ -312,6 +313,10 @@ class Types(models.TextChoices):
class Meta:
indexes = [
GinIndex(fields=["hashtags"], name="hashtags_gin"),
GinIndex(
SearchVector("content", config="english"),
name="content_vector_gin",
),
models.Index(
fields=["visibility", "local", "published"],
name="ix_post_local_public_published",
Expand Down
8 changes: 6 additions & 2 deletions activities/services/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ def boost_as(self, identity: Identity):
def unboost_as(self, identity: Identity):
self.uninteract_as(identity, PostInteraction.Types.boost)

def context(self, identity: Identity | None) -> tuple[list[Post], list[Post]]:
def context(
self,
identity: Identity | None,
num_ancestors: int = 10,
num_descendants: int = 50,
) -> tuple[list[Post], list[Post]]:
"""
Returns ancestor/descendant information.
Expand All @@ -82,7 +87,6 @@ def context(self, identity: Identity | None) -> tuple[list[Post], list[Post]]:
If identity is provided, includes mentions/followers-only posts they
can see. Otherwise, shows unlisted and above only.
"""
num_ancestors = 10
num_descendants = 50
# Retrieve ancestors via parent walk
ancestors: list[Post] = []
Expand Down
6 changes: 6 additions & 0 deletions activities/services/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ def search_hashtags(self) -> set[Hashtag]:
results.add(hashtag)
return results

def search_post_content(self):
"""
Searches for posts on an identity via full text search
"""
return self.identity.posts.filter(content__search=self.query)[:50]

def search_all(self):
"""
Returns all possible results for a search
Expand Down
5 changes: 4 additions & 1 deletion activities/services/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ def home(self) -> models.QuerySet[TimelineEvent]:
)

def local(self) -> models.QuerySet[Post]:
return (
queryset = (
PostService.queryset()
.local_public()
.filter(author__restriction=Identity.Restriction.none)
.order_by("-id")
)
if self.identity is not None:
queryset = queryset.filter(author__domain=self.identity.domain)
return queryset

def federated(self) -> models.QuerySet[Post]:
return (
Expand Down
Loading

0 comments on commit 8f57aa5

Please sign in to comment.