In Vakil's notes on the foundations of algebraic geometry, he defines the structure sheaf $ \mathscr{O}_{\text{Spec}A}(D(f))$ for distinguished open sets $D(f)$ by $\mathscr{O}_{\text{Spec}A}(D(f)) := A_f$. He then defines the restriction map for $D(g) \subseteq D(f)$ by
$$\rho^{D(f)}_{D(g)} : \mathscr{O}_{\text{Spec}A}(D(f)) \rightarrow \mathscr{O}_{\text{Spec}A}(D(g))$$
"in the obvious way". I assume this means
$$\frac{a}{f^{n}} \mapsto \frac{b^{m}a}{g^{mn}}?$$
He then goes on and proves that this is indeed a sheaf of rings on the distinguished open sets. Now, he claims that this then indeed gives a sheaf of rings on the topological space Spec $A$. I know that every open set $U$ of Spec $A$ may be written as the union of distinguished open sets such that
$$U = \bigcup_{i \in I} D(f_{i}).$$
But how do I get the sheaf $\mathscr{O}_{\text{Spec}A}(U)$? I.e. is this the localization at the sum $\sum_{i \in I} f_i$ or the product of the $A_{f_{i}}$?