Query with reckless abandon
TLDR
We deduplicate queries for faster, more efficient database performance, and add support for multi-file schemas in the Triplit CLI.
Repeated queries are more efficient over the network
When using the Triplit Client as a state manager, you may find yourself querying the same data multiple times in different components. Previously, each query would be sent over the network, even if the data was already in the cache. This would result in redundant data being sent back to the client, which would be discarded but consume bandwidth and slow database performance. With this weeks change, the Triplit Client will now deduplicate queries that are identical, and only send them once over the network. This will result in a significant reduction in network traffic and faster database performance if you're using this pattern.
import { useQuery } from '@triplit/client';
import { client } from './client';
// invoke this function in multiple components
// the query will only be sent once over the network
function useTodos() {
return useQuery(client, client.query('todos'));
}
function TodosList() {
const { results, fetching } = useTodos();
if (fetching) return <div>Loading...</div>;
return (
<div>
{Array.from(results).map((todo) => (
<div>{todo.text}</div>
))}
</div>
);
}
function TodosCount() {
const { results, fetching } = useTodos();
if (fetching) return <div>Loading...</div>;
return <div>{results.size}</div>;
}
function App() {
return (
<div>
<TodosList />
<TodosCount />
</div>
);
}
Multi-file schemas now work with the Triplit CLI
As the Triplit schema API has grown to encompass roles and permissions, the need for multi-file schemas has become more apparent. This week we've added support for multi-file schemas in the Triplit CLI. You can now split your schema into multiple files and import them into your main schema file. This will make it easier to manage large schemas and share common definitions.
Other improvements
- We've added a section to the documentation describing the best way to store user profile data when using external authentication.
- The Triplit CLI will now pick up
.env.local
files in the root of your project, in addition to.env
files. - The
scope
claim in JWTs is now parsed into an array of strings and stored in an additional_scope
claim. This allows you to write permission filters that check against a user's scope using thein
operator. Eventually we plan to supplant this with support for functions in query filters likesplit($role.scope)
.