Chapter 8 - use dynamic rendering and simulate timeout
This commit is contained in:
@@ -9,21 +9,23 @@ import {
|
||||
Revenue,
|
||||
} from './definitions';
|
||||
import { formatCurrency } from './utils';
|
||||
import {unstable_noStore as noStore} from "next/cache";
|
||||
|
||||
export async function fetchRevenue() {
|
||||
// Add noStore() here prevent the response from being cached.
|
||||
// This is equivalent to in fetch(..., {cache: 'no-store'}).
|
||||
noStore()
|
||||
|
||||
try {
|
||||
// Artificially delay a response for demo purposes.
|
||||
// Don't do this in production :)
|
||||
|
||||
// console.log('Fetching revenue data...');
|
||||
// await new Promise((resolve) => setTimeout(resolve, 3000));
|
||||
console.log('Fetching revenue data...');
|
||||
await new Promise((resolve) => setTimeout(resolve, 3000));
|
||||
|
||||
const data = await sql<Revenue>`SELECT * FROM revenue`;
|
||||
|
||||
// console.log('Data fetch completed after 3 seconds.');
|
||||
console.log('Data fetch completed after 3 seconds.');
|
||||
|
||||
return data.rows;
|
||||
} catch (error) {
|
||||
@@ -33,6 +35,7 @@ export async function fetchRevenue() {
|
||||
}
|
||||
|
||||
export async function fetchLatestInvoices() {
|
||||
noStore();
|
||||
try {
|
||||
const data = await sql<LatestInvoiceRaw>`
|
||||
SELECT invoices.amount, customers.name, customers.image_url, customers.email, invoices.id
|
||||
@@ -53,6 +56,7 @@ export async function fetchLatestInvoices() {
|
||||
}
|
||||
|
||||
export async function fetchCardData() {
|
||||
noStore();
|
||||
try {
|
||||
// You can probably combine these into a single SQL query
|
||||
// However, we are intentionally splitting them to demonstrate
|
||||
@@ -92,6 +96,7 @@ export async function fetchFilteredInvoices(
|
||||
query: string,
|
||||
currentPage: number,
|
||||
) {
|
||||
noStore();
|
||||
const offset = (currentPage - 1) * ITEMS_PER_PAGE;
|
||||
|
||||
try {
|
||||
@@ -124,6 +129,7 @@ export async function fetchFilteredInvoices(
|
||||
}
|
||||
|
||||
export async function fetchInvoicesPages(query: string) {
|
||||
noStore();
|
||||
try {
|
||||
const count = await sql`SELECT COUNT(*)
|
||||
FROM invoices
|
||||
@@ -145,6 +151,7 @@ export async function fetchInvoicesPages(query: string) {
|
||||
}
|
||||
|
||||
export async function fetchInvoiceById(id: string) {
|
||||
noStore();
|
||||
try {
|
||||
const data = await sql<InvoiceForm>`
|
||||
SELECT
|
||||
@@ -170,6 +177,7 @@ export async function fetchInvoiceById(id: string) {
|
||||
}
|
||||
|
||||
export async function fetchCustomers() {
|
||||
noStore();
|
||||
try {
|
||||
const data = await sql<CustomerField>`
|
||||
SELECT
|
||||
@@ -188,6 +196,7 @@ export async function fetchCustomers() {
|
||||
}
|
||||
|
||||
export async function fetchFilteredCustomers(query: string) {
|
||||
noStore();
|
||||
try {
|
||||
const data = await sql<CustomersTableType>`
|
||||
SELECT
|
||||
|
||||
Reference in New Issue
Block a user