bulltrackers-module 1.0.605 → 1.0.606

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1846,7 +1846,84 @@ const getSyncStatus = async (db, targetId) => {
1846
1846
  const isProcessingState = processingStates.includes(currentStatus);
1847
1847
 
1848
1848
  if (isProcessingState) {
1849
- // Check age of request
1849
+ // First, check if computation results exist (computation may have completed but status wasn't updated)
1850
+ // This is especially important for "computing" status
1851
+ if (currentStatus === 'computing' || currentStatus === 'indexing') {
1852
+ try {
1853
+ const today = new Date().toISOString().split('T')[0];
1854
+ const userType = data.userType || 'SIGNED_IN_USER';
1855
+
1856
+ // Determine which computation to check based on user type
1857
+ let computationNames = [];
1858
+ if (userType === 'POPULAR_INVESTOR') {
1859
+ computationNames = ['PopularInvestorProfileMetrics'];
1860
+ // Check if also a signed-in user
1861
+ try {
1862
+ await isSignedInUser(db, targetId);
1863
+ computationNames.push('SignedInUserPIPersonalizedMetrics');
1864
+ } catch (e) {
1865
+ // Not a signed-in user
1866
+ }
1867
+ } else {
1868
+ computationNames = ['SignedInUserProfileMetrics'];
1869
+ // Check if also a PI
1870
+ try {
1871
+ await fetchPopularInvestorMasterList(db, String(targetId));
1872
+ computationNames.push('SignedInUserPIPersonalizedMetrics', 'PopularInvestorProfileMetrics');
1873
+ } catch (e) {
1874
+ // Not a PI
1875
+ }
1876
+ }
1877
+
1878
+ // Check if any computation results exist for today
1879
+ let computationFound = false;
1880
+ for (const compName of computationNames) {
1881
+ try {
1882
+ const pageRef = db.collection('unified_insights')
1883
+ .doc(today)
1884
+ .collection('results')
1885
+ .doc('popular-investor')
1886
+ .collection('computations')
1887
+ .doc(compName)
1888
+ .collection('pages')
1889
+ .doc(String(targetId));
1890
+
1891
+ const pageSnap = await pageRef.get();
1892
+ if (pageSnap.exists) {
1893
+ computationFound = true;
1894
+ break;
1895
+ }
1896
+ } catch (error) {
1897
+ // Continue checking other computations
1898
+ console.error(`Error checking computation ${compName} for ${today}:`, error);
1899
+ }
1900
+ }
1901
+
1902
+ // If computation results exist, mark as completed
1903
+ if (computationFound) {
1904
+ await doc.ref.update({
1905
+ status: 'completed',
1906
+ completedAt: new Date(),
1907
+ updatedAt: new Date()
1908
+ });
1909
+
1910
+ return {
1911
+ requestId: requestId,
1912
+ status: 'completed',
1913
+ type: data.userType,
1914
+ createdAt: data.createdAt ? (data.createdAt.toDate ? data.createdAt.toDate().toISOString() : (data.createdAt.toISOString ? data.createdAt.toISOString() : data.createdAt)) : null,
1915
+ updatedAt: new Date().toISOString(),
1916
+ completedAt: new Date().toISOString(),
1917
+ canRequest: true
1918
+ };
1919
+ }
1920
+ } catch (error) {
1921
+ // If error checking computation results, continue with timeout check
1922
+ console.error(`[getSyncStatus] Error checking computation results:`, error);
1923
+ }
1924
+ }
1925
+
1926
+ // Check age of request for timeout
1850
1927
  const createdAt = data.createdAt;
1851
1928
  const updatedAt = data.updatedAt;
1852
1929
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.605",
3
+ "version": "1.0.606",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [