39
39
WikiPageSynchronousProtocol ,
40
40
)
41
41
42
+ # File size threshold for using single-threaded vs multi-threaded download (8 MiB)
43
+ SINGLE_THREAD_DOWNLOAD_SIZE_LIMIT = 8 * 1024 * 1024 # 8 MiB in bytes
44
+
42
45
43
46
@dataclass
44
47
@async_to_sync
@@ -146,6 +149,7 @@ async def get_async(
146
149
"""
147
150
if not self .owner_id :
148
151
raise ValueError ("Must provide owner_id to get wiki order hint." )
152
+
149
153
order_hint_dict = await get_wiki_order_hint (
150
154
owner_id = self .owner_id ,
151
155
synapse_client = synapse_client ,
@@ -554,7 +558,7 @@ async def task_of_uploading_attachment(attachment: str) -> tuple[str, str]:
554
558
parent_entity_id = self .owner_id ,
555
559
path = file_path ,
556
560
)
557
- synapse_client .logger .info (
561
+ synapse_client .logger .debug (
558
562
f"Uploaded file handle { file_handle .get ('id' )} for wiki page attachment."
559
563
)
560
564
return file_handle .get ("id" )
@@ -851,11 +855,10 @@ async def get_attachment_handles_async(
851
855
)
852
856
async def get_attachment_async (
853
857
self ,
854
- file_name : str ,
855
858
* ,
859
+ file_name : str ,
856
860
download_file : bool = True ,
857
861
download_location : Optional [str ] = None ,
858
- redirect : Optional [bool ] = False ,
859
862
synapse_client : Optional ["Synapse" ] = None ,
860
863
) -> Union [str , None ]:
861
864
"""
@@ -865,7 +868,6 @@ async def get_attachment_async(
865
868
file_name: The name of the file to get.
866
869
download_file: Whether associated files should be downloaded. Default is True.
867
870
download_location: The directory to download the file to. Required if download_file is True.
868
- redirect: When set to false, the URL will be returned as text/plain instead of redirecting. Default is False.
869
871
synapse_client: Optionally provide a Synapse client.
870
872
Returns:
871
873
If download_file is True, the attachment file will be downloaded to the download_location. Otherwise, the URL will be returned.
@@ -885,7 +887,6 @@ async def get_attachment_async(
885
887
wiki_id = self .id ,
886
888
file_name = file_name ,
887
889
wiki_version = self .wiki_version ,
888
- redirect = redirect ,
889
890
synapse_client = client ,
890
891
)
891
892
@@ -908,7 +909,7 @@ async def get_attachment_async(
908
909
# check the file_size
909
910
file_size = int (WikiPage ._get_file_size (filehandle_dict , file_name ))
910
911
# use single thread download if file size < 8 MiB
911
- if file_size < 8388608 :
912
+ if file_size < SINGLE_THREAD_DOWNLOAD_SIZE_LIMIT :
912
913
download_from_url (
913
914
url = presigned_url_info .url ,
914
915
destination = download_location ,
@@ -934,7 +935,6 @@ async def get_attachment_preview_async(
934
935
* ,
935
936
download_file : bool = True ,
936
937
download_location : Optional [str ] = None ,
937
- redirect : Optional [bool ] = False ,
938
938
synapse_client : Optional ["Synapse" ] = None ,
939
939
) -> Union [str , None ]:
940
940
"""
@@ -944,7 +944,6 @@ async def get_attachment_preview_async(
944
944
file_name: The name of the file to get.
945
945
download_file: Whether associated files should be downloaded. Default is True.
946
946
download_location: The directory to download the file to. Required if download_file is True.
947
- redirect: When set to false, the URL will be returned as text/plain instead of redirecting. Default is False.
948
947
synapse_client: Optionally provide a Synapse client.
949
948
Returns:
950
949
If download_file is True, the attachment preview file will be downloaded to the download_location. Otherwise, the URL will be returned.
@@ -964,7 +963,6 @@ async def get_attachment_preview_async(
964
963
wiki_id = self .id ,
965
964
file_name = file_name ,
966
965
wiki_version = self .wiki_version ,
967
- redirect = redirect ,
968
966
synapse_client = client ,
969
967
)
970
968
# download the file if download_file is True
@@ -988,7 +986,7 @@ async def get_attachment_preview_async(
988
986
# check the file_size
989
987
file_size = int (WikiPage ._get_file_size (filehandle_dict , file_name ))
990
988
# use single thread download if file size < 8 MiB
991
- if file_size < 8388608 :
989
+ if file_size < SINGLE_THREAD_DOWNLOAD_SIZE_LIMIT :
992
990
download_from_url (
993
991
url = presigned_url_info .url ,
994
992
destination = download_location ,
@@ -997,11 +995,11 @@ async def get_attachment_preview_async(
997
995
else :
998
996
# download the file
999
997
download_from_url_multi_threaded (
1000
- presigned_url = presigned_url_info .url , destination = download_location
1001
- )
1002
- client .logger .debug (
1003
- f"Downloaded the preview file { presigned_url_info .file_name } to { download_location } "
998
+ presigned_url = presigned_url_info , destination = download_location
1004
999
)
1000
+ client .logger .debug (
1001
+ f"Downloaded the preview file { presigned_url_info .file_name } to { download_location } "
1002
+ )
1005
1003
else :
1006
1004
return attachment_preview_url
1007
1005
@@ -1014,7 +1012,6 @@ async def get_markdown_async(
1014
1012
download_file_name : Optional [str ] = None ,
1015
1013
download_file : bool = True ,
1016
1014
download_location : Optional [str ] = None ,
1017
- redirect : Optional [bool ] = False ,
1018
1015
synapse_client : Optional ["Synapse" ] = None ,
1019
1016
) -> Union [str , None ]:
1020
1017
"""
@@ -1024,7 +1021,6 @@ async def get_markdown_async(
1024
1021
download_file_name: The name of the file to download. Required if download_file is True.
1025
1022
download_file: Whether associated files should be downloaded. Default is True.
1026
1023
download_location: The directory to download the file to. Required if download_file is True.
1027
- redirect: When set to false, the URL will be returned as text/plain instead of redirecting. Default is False.
1028
1024
synapse_client: Optionally provide a Synapse client.
1029
1025
Returns:
1030
1026
If download_file is True, the markdown file will be downloaded to the download_location. Otherwise, the URL will be returned.
@@ -1041,7 +1037,6 @@ async def get_markdown_async(
1041
1037
owner_id = self .owner_id ,
1042
1038
wiki_id = self .id ,
1043
1039
wiki_version = self .wiki_version ,
1044
- redirect = redirect ,
1045
1040
synapse_client = client ,
1046
1041
)
1047
1042
# download the file if download_file is True
@@ -1067,17 +1062,3 @@ async def get_markdown_async(
1067
1062
)
1068
1063
else :
1069
1064
return markdown_url
1070
-
1071
- @classmethod
1072
- def from_dict (
1073
- cls , synapse_wiki : Dict [str , Union [str , List [str ], List [Dict [str , Any ]]]]
1074
- ) -> "WikiPage" :
1075
- """Create a new WikiPage instance from a dictionary.
1076
-
1077
- Arguments:
1078
- synapse_wiki: The dictionary containing wiki page data.
1079
-
1080
- Returns:
1081
- A new WikiPage instance filled with the dictionary data.
1082
- """
1083
- return cls ().fill_from_dict (synapse_wiki )
0 commit comments