Skip to content

Commit

Permalink
Revert "Join bulk annotation data with annotation metadata"
Browse files Browse the repository at this point in the history
This reverts commit 4b43670.
  • Loading branch information
marcospri committed Sep 18, 2023
1 parent 442198c commit cfb67b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 29 deletions.
26 changes: 5 additions & 21 deletions h/services/bulk_annotation.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
from dataclasses import dataclass, field
from typing import List, Optional
from dataclasses import dataclass
from typing import List

import sqlalchemy as sa
from sqlalchemy.orm import Session
from sqlalchemy.sql import Select

from h.models import (
Annotation,
AnnotationMetadata,
AnnotationModeration,
Group,
GroupMembership,
User,
)
from h.models import Annotation, AnnotationModeration, Group, GroupMembership, User


class BadDateFilter(Exception):
Expand Down Expand Up @@ -65,7 +58,6 @@ def date_match(column: sa.Column, spec: dict):
class BulkAnnotation:
username: str
authority_provided_id: str
metadata: Optional[dict] = field(default_factory=dict)


class BulkAnnotationService:
Expand Down Expand Up @@ -109,9 +101,7 @@ def annotation_search(

return [
BulkAnnotation(
username=row.username,
authority_provided_id=row.authority_provided_id,
metadata=row.metadata,
username=row.username, authority_provided_id=row.authority_provided_id
)
for row in results.all()
]
Expand All @@ -120,15 +110,9 @@ def annotation_search(
def _search_query(cls, authority, audience, updated) -> Select:
"""Generate a query which can then be executed to find annotations."""
query = sa.select(
[
cls._AUTHOR.username,
Group.authority_provided_id,
sa.func.coalesce(AnnotationMetadata.data, "{}").label("metadata"),
]
[cls._AUTHOR.username, Group.authority_provided_id]
).select_from(Annotation)

# Metadata
query = query.outerjoin(AnnotationMetadata)
# Updated
query = query.where(date_match(Annotation.updated, updated))

Expand Down
8 changes: 0 additions & 8 deletions tests/h/services/bulk_annotation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ class TestBulkAnnotationService:
("shared", False, False),
("deleted", True, False),
("nipsad", True, False),
("with_metadata", True, True),
("with_metadata", False, True),
("moderated", True, False),
("updated", "2020-01-01", False),
("updated", "2020-01-02", True),
Expand All @@ -77,7 +75,6 @@ class TestBulkAnnotationService:
)
def test_it_with_single_annotation(self, svc, factories, key, value, visible):
values = {
"with_metadata": True,
"shared": True,
"deleted": False,
"nipsad": False,
Expand All @@ -96,14 +93,10 @@ def test_it_with_single_annotation(self, svc, factories, key, value, visible):
shared=values["shared"],
deleted=values["deleted"],
updated=values["updated"],
pk=1,
)
if values["moderated"]:
factories.AnnotationModeration(annotation=anno)

if values["with_metadata"]:
factories.AnnotationMetadata(annotation=anno, data={"some": "value"})

annotations = svc.annotation_search(
authority=self.AUTHORITY,
audience={"username": [viewer.username]},
Expand All @@ -115,7 +108,6 @@ def test_it_with_single_annotation(self, svc, factories, key, value, visible):
BulkAnnotation(
username=author.username,
authority_provided_id=group.authority_provided_id,
metadata={"some": "value"} if values["with_metadata"] else {},
)
]
else:
Expand Down

0 comments on commit cfb67b3

Please sign in to comment.