PageSourceSearch

https://fyra.life/assets/ratingsCache-Dsu4g_xe.js

js fyra.life collected 2026-10-02 01:59:33 UTC 4,407 bytes, 1 lines download raw bytes

1import{an as b,ao as k,ap as D,s as x}from"./index-CEISlULX.js";const g=2,A=k("fyra-ratings-cache","rows"),O=t=>`ratings:${t}`,C=t=>`fyra:ratings:${t}`,I=2500;function P(t){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(C(t));if(!e)return null;const n=JSON.parse(e);return!n||n.v!==g||n.userId!==t||!n.ratings||typeof n.ratings!="object"?null:n}catch{return null}}function E(t){if(!(typeof window>"u"))try{const e=Object.entries(t.ratings);if(e.length>I){e.sort((a,r)=>(r[1].updated_at||"").localeCompare(a[1].updated_at||""));const n={};for(const[a,r]of e.slice(0,I))n[a]=r;t={...t,ratings:n,partial:!0}}else t={...t,partial:!1};window.localStorage.setItem(C(j(t)),JSON.stringify(t))}catch{}}const j=t=>t.userId;function N(t){const e=P(t);return(e==null?void 0:e.ratings)??null}async function w(t){const e=P(t);if(e&&!e.partial)return e;try{const n=await Promise.race([b(O(t),A),new Promise(a=>setTimeout(()=>a(void 0),1500))]);return!n||n.v!==g||n.userId!==t?e??null:n}catch{return e??null}}async function S(t){E(t);try{await D(O(t.userId),t,A)}catch{}}async function y(t,e,n){await S({v:g,userId:t,ratings:e,lastSyncedAt:n})}async function G(t,e,n){const a=await w(t)??{v:g,userId:t,ratings:{},lastSyncedAt:new Date().toISOString()},r={...a,v:g,userId:t,ratings:{...a.ratings,[e]:n}};await S(r)}async function J(t,e){const n=await w(t);if(!n||!(e in n.ratings))return;const a={...n.ratings};delete a[e],await S({...n,ratings:a})}const f=new Map,i=1e3,p=50;function _(t,e){return x.from("user_taste_ratings").select("vault_taste_id, rating_value, experienced_state, updated_at").eq("user_id",t).order("updated_at",{ascending:!1,nullsFirst:!1}).range(e,e+i-1)}function h(t,e,n){for(const a of t)a!=null&&a.vault_taste_id&&(e[String(a.vault_taste_id)]={rating_value:a.rating_value,experienced_state:a.experienced_state,updated_at:a.updated_at},a.updated_at&&a.updated_at>n.maxUpdated&&(n.maxUpdated=a.updated_at))}async function U(t){const e={},n={maxUpdated:""};let a=0;for(;;){const{data:r,error:s}=await _(t,a);if(s)throw s;const o=r??[];if(h(o,e,n),o.length<i||(a+=i,a>=i*p))break}return{map:e,maxUpdated:n.maxUpdated||new Date().toISOString()}}async function R(t){try{const{count:e,error:n}=await x.from("user_taste_ratings").select("vault_taste_id",{count:"exact",head:!0}).eq("user_id",t);if(n)throw n;const a=e??0;if(a===0){const{data:c,error:d}=await _(t,0);if(d)throw d;const u={},l={maxUpdated:""};return h(c??[],u,l),(c??[]).length>=i?U(t):{map:u,maxUpdated:l.maxUpdated||new Date().toISOString()}}const r=Math.min(Math.ceil(a/i),p),s=await Promise.all(Array.from({length:r},(c,d)=>_(t,d*i))),o={},m={maxUpdated:""};let v=0;for(const c of s){if(c.error)throw c.error;const d=c.data??[];v+=d.length,h(d,o,m)}if(v>=r*i&&r<p){let c=r*i;for(;c<i*p;){const{data:d,error:u}=await _(t,c);if(u)throw u;const l=d??[];if(h(l,o,m),l.length<i)break;c+=i}}return{map:o,maxUpdated:m.maxUpdated||new Date().toISOString()}}catch{return U(t)}}async function q(t,e){const{data:n,error:a}=await x.from("user_taste_ratings").select("vault_taste_id, rating_value, experienced_state, updated_at").eq("user_id",t).gt("updated_at",e).limit(5e3);if(a)throw a;const r={};for(const s of n??[])s!=null&&s.vault_taste_id&&(r[String(s.vault_taste_id)]={rating_value:s.rating_value,experienced_state:s.experienced_state,updated_at:s.updated_at});return r}async function F(t){const e=await w(t);if(!e||e.partial){const a=(async()=>{const{map:r,maxUpdated:s}=await R(t);return await y(t,r,s),r})();return{cached:(e==null?void 0:e.ratings)??null,fresh:a}}const n=(async()=>{try{const a=await q(t,e.lastSyncedAt);if(Object.keys(a).length===0)return e.ratings;const r={...e.ratings,...a};let s=e.lastSyncedAt;for(const o of Object.values(a))o.updated_at&&o.updated_at>s&&(s=o.updated_at);return await y(t,r,s),r}catch{try{const{map:a,maxUpdated:r}=await R(t);return await y(t,a,r),a}catch{return e.ratings}}})();return{cached:e.ratings,fresh:n}}async function M(t){const e=f.get(t);if(e){const a=await w(t);return{cached:(a==null?void 0:a.ratings)??null,fresh:e}}const n=await F(t);return f.set(t,n.fresh),n.fresh.finally(()=>{f.get(t)===n.fresh&&f.delete(t)}),n}function $(t){!t||f.has(t)||M(t).then(e=>e.fresh.catch(()=>{})).catch(()=>{})}export{w as getCachedRatings,N as getCachedRatingsSync,M as loadRatings,G as patchCachedRating,$ as prefetchRatings,J as removeCachedRating,y as setCac
1hedRatings};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.