fix: Increase speed on censures and hesitations GET

pull/54/head
db0 2023-10-15 19:18:06 +02:00
parent d380f34364
commit b44529242d
5 changed files with 12 additions and 5 deletions

View File

@ -1,5 +1,10 @@
# Changelog
# 0.21.0
* Added rebuttals
* Improved speed of GET on /hesitations and /censures
# 0.20.1
* Allow filtering by software

View File

@ -154,10 +154,10 @@ class Censures(Resource):
if p_instance != get_instance:
continue
instances.append(p_instance)
censures = database.get_all_censure_reasons_for_censured_id(instance.id, [c.id for c in instances])
rebuttals = database.get_all_rebuttals_from_source_instance_id(instance.id,[c.id for c in instances])
for c_instance in instances:
censures = database.get_all_censure_reasons_for_censured_id(instance.id, [c_instance.id])
censures = [c for c in censures if c.reason is not None]
censures = [c for c in censures if c.reason is not None and c.censuring_id == c_instance.id]
c_instance_details = c_instance.get_details()
if len(censures) > 0:
c_instance_details["censure_reasons"] = [censure.reason for censure in censures]

View File

@ -140,10 +140,10 @@ class Hesitations(Resource):
continue
instances.append(p_instance)
instance_details = []
hesitations = database.get_all_hesitation_reasons_for_dubious_id(instance.id, [c.id for c in instances])
rebuttals = database.get_all_rebuttals_from_source_instance_id(instance.id,[c.id for c in instances])
for c_instance in instances:
hesitations = database.get_all_hesitation_reasons_for_dubious_id(instance.id, [c_instance.id])
hesitations = [c for c in hesitations if c.reason is not None]
hesitations = [c for c in hesitations if c.reason is not None and c.hesitant_id == c_instance.id]
c_instance_details = c_instance.get_details()
if len(hesitations) > 0:
c_instance_details["hesitation_reasons"] = [hesitation.reason for hesitation in hesitations]

View File

@ -1,4 +1,4 @@
FEDISEER_VERSION = "0.20.0"
FEDISEER_VERSION = "0.22.0"
SUPPORTED_SOFTWARE = {
"lemmy",
"mastodon",

View File

@ -147,6 +147,7 @@ def get_all_censure_reasons_for_censured_id(censured_id, censuring_ids):
Censure.censured_id == censured_id,
Censure.censuring_id.in_(censuring_ids),
).with_entities(
Censure.censuring_id,
Censure.reason,
Censure.evidence,
)
@ -199,6 +200,7 @@ def get_all_hesitation_reasons_for_dubious_id(dubious_id, hesitant_ids):
Hesitation.dubious_id == dubious_id,
Hesitation.hesitant_id.in_(hesitant_ids),
).with_entities(
Hesitation.hesitant_id,
Hesitation.reason,
Hesitation.evidence,
)