Skip to content

Commit 8e6bfc0

Browse files
committed
add timeouts to airtable api calls
1 parent bde1dea commit 8e6bfc0

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

ddlh/airtable.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import os
22
from dataclasses import dataclass
3+
from time import sleep
34
from typing import Optional, Sequence
45

56
from pyairtable import Api
67
from pyairtable.api.types import RecordDict
78

89
from ddlh.redis_cache import RedisCache, create_cache
910

11+
# Maximum 5 requests per second per base:
12+
# see https://airtable.com/developers/web/api/rate-limits
13+
REQUEST_TIMEOUT = 1 / 5.0
14+
1015

1116
@dataclass
1217
class AirtableConfig:
@@ -31,15 +36,19 @@ def get(self, table_name: str, id: str) -> Optional[RecordDict]:
3136
def _uncached_all(self, table_name: str) -> Sequence[RecordDict]:
3237
table_id = self._table_id(table_name)
3338
if table_id:
34-
return self.api.table(self.config.base_id, table_id).all(
39+
result = self.api.table(self.config.base_id, table_id).all(
3540
view=self._view_id(table_name)
3641
)
42+
sleep(REQUEST_TIMEOUT)
43+
return result
3744
return []
3845

3946
def _uncached_get(self, table_name: str, id: str) -> Optional[RecordDict]:
4047
table_id = self._table_id(table_name)
4148
if table_id:
42-
return self.api.table(self.config.base_id, table_id).get(id)
49+
result = self.api.table(self.config.base_id, table_id).get(id)
50+
sleep(REQUEST_TIMEOUT)
51+
return result
4352
return None
4453

4554
def _table_id(self, table_name: str) -> Optional[str]:

ddlh/static/styles.css

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@
8383
font-weight: 100 900;
8484
font-display: swap;
8585
src: url("/static/fonts/WorkSans-Italic-LatinExt.woff2") format("woff2");
86-
unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF,
87-
U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
86+
unicode-range:
87+
U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
88+
U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
8889
}
8990

9091
/* latin */
@@ -94,9 +95,10 @@
9495
font-weight: 100 900;
9596
font-display: swap;
9697
src: url("/static/fonts/WorkSans-Italic-Latin.woff2") format("woff2");
97-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
98-
U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191,
99-
U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
98+
unicode-range:
99+
U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
100+
U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193,
101+
U+2212, U+2215, U+FEFF, U+FFFD;
100102
}
101103

102104
/* latin-ext */
@@ -106,8 +108,9 @@
106108
font-weight: 100 900;
107109
font-display: swap;
108110
src: url("/static/fonts/WorkSans-Normal-LatinExt.woff2") format("woff2");
109-
unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF,
110-
U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
111+
unicode-range:
112+
U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
113+
U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
111114
}
112115

113116
/* latin */
@@ -117,9 +120,10 @@
117120
font-weight: 100 900;
118121
font-display: swap;
119122
src: url("/static/fonts/WorkSans-Normal-Latin.woff2") format("woff2");
120-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
121-
U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191,
122-
U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
123+
unicode-range:
124+
U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
125+
U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193,
126+
U+2212, U+2215, U+FEFF, U+FFFD;
123127
}
124128

125129
/*

ddlh/templates/layouts/main.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
<link rel="shortcut icon"
1515
href="{{ url_for("static", filename="favicon.ico") }}">
1616
<title>{{ breadcrumbs|page_title_from_breadcrumbs }}</title>
17-
<script defer data-domain="learn.distributeddesign.eu" src="https://plausible.io/js/script.js"></script>
17+
<script defer
18+
data-domain="learn.distributeddesign.eu"
19+
src="https://plausible.io/js/script.js"></script>
1820
</head>
1921
<body>
2022
{% include "partials/header.j2" %}

0 commit comments

Comments
 (0)